Condividi:        

problema con macro

Vuoi potenziare i tuoi documenti Word? Non sai come si fa una macro in Excel? Devi creare una presentazione in PowerPoint?
Oppure sei passato a OpenOffice e non sei sicuro di come lavorare al meglio?

Moderatori: Anthony47, Flash30005

problema con macro

Postdi rombotuono » 30/10/21 12:57

buongiorno
dopo aggiornamento windows 11 la macro si blocca in questo punto Resume Uscita con questo errore 462 il computer server remoto
non esiste o non è disponibile
il link è questo https://www.betexplorer.com/soccer/arge ... ofesional/


Sub importa_torneo()
Application.ScreenUpdating = False
Sheets("dati").Activate
Call Importa_classifica_home

Dim mIE As Object
Dim mTables, mTable
Dim mRows, mRow
Dim mCells, mCell
Dim mRiga As Long, mColonna As Long
Dim k As Integer, k1 As Integer, n As String, f As Integer
Dim flag1 As Boolean
On Error GoTo errori


If Range("ao1") = "" Then
MsgBox "Inserire in l1 il numero della tabella da stampare"
Exit Sub
End If
n = Range("ao1")
Range("ap2:ay800").ClearContents
mRiga = 2
k = 0
f = 0
k1 = 0
Set mIE = CreateObject("InternetExplorer.Application")

With mIE
.AddressBar = False
.StatusBar = False
.MenuBar = False
.Toolbar = 0
.Visible = False ' True= fa vedere la pagina web
.navigate Range("ap1").Value '"http://data2.7m.cn/team_data/212/en/index.shtml"
End With

'Attesa finchè la pagina non è completamente caricata
While mIE.Busy
Wend
While mIE.document.readyState <> "complete"
Wend

Set mTables = mIE.document.all.tags("TABLE")

With mTables
' If .WebTables = (0) Then 'CStr(Range("l1").Value) Then
For Each mTable In mTables
k1 = k1 + 1
If k1 = n Then
f = f + 1
Set mRows = mTable.Rows
For Each mRow In mRows
Set mCells = mRow.Cells
If Cells(mRiga - 1, 1) = "" Or Cells(mRiga - 1, 1) = "No." Then
mColonna = 41
Else
mColonna = 41
End If
If k = 1 Then mColonna = 41
For Each mCell In mCells
ActiveSheet.Cells(mRiga, mColonna) = mCell.innerText
mColonna = mColonna + 1
Next mCell
mRiga = mRiga + 1
Next mRow
k = 1
If f = 1 Then
Range("j1:j" & mRiga - 1).Select
Selection.Style = "Comma"
k1 = k1 - 1
End If
End If
Next mTable
' End If
End With


Uscita:
Set mCell = Nothing
Set mCells = Nothing
Set mRow = Nothing
Set mRows = Nothing
Set mTable = Nothing
Set mTables = Nothing
mIE.Quit
Set mIE = Nothing
Exit Sub
errori:
MsgBox Err.Number & "-" & Err.Description
Resume Uscita
End Sub
rombotuono
Utente Senior
 
Post: 112
Iscritto il: 09/11/18 17:27

Sponsor
 

Re: problema con macro

Postdi Anthony47 » 30/10/21 14:47

Su windows 11 credo che InternetExplorer non sia più disponibile, quindi le macro basate su IE non dovrebbero più funzionare.
Esistono "drivers" in grado di abilitare l'accesso vba ai nuovi browser, ma richiedono una predisposizione di sistema non proprio elementare; ma prima o poi lo dovrò descrivere. E comunque tutte le macro saranno da riscrivere, anche se molti comandi sono mappati uno-a-uno
Ciao
Avatar utente
Anthony47
Moderatore
 
Post: 19213
Iscritto il: 21/03/06 16:03
Località: Ivrea

Re: problema con macro

Postdi rombotuono » 30/10/21 14:59

grazie
rombotuono
Utente Senior
 
Post: 112
Iscritto il: 09/11/18 17:27

Re: problema con macro

Postdi rombotuono » 31/10/21 17:50

buongiorno
ho provato con il registratore macro ad importare la tabella che mi interessa su windows 11 ma non mi permette di caricarla nuovamente perchè la querry è già presente con lo stesso nome.
visto che ho bisogno di importare nello stesso range tabelle con link diversi
grazie
allego file http://www.filedropper.com/prova_4
questa è la macro registrata
Codice: Seleziona tutto
Sub prova()
'
'
'

'
    Sheets("pp").Select
    Range("M1").Select
    Selection.Copy
    Application.CutCopyMode = False
    ActiveWorkbook.Queries.Add Name:="Table 0 (3)", Formula:= _
        "let" & Chr(13) & "" & Chr(10) & "    Origine = Web.Page(Web.Contents(""https://www.betexplorer.com/soccer/argentina/primera-nacional/""))," & Chr(13) & "" & Chr(10) & "    Data0 = Origine{0}[Data]," & Chr(13) & "" & Chr(10) & "    #""Modificato tipo"" = Table.TransformColumnTypes(Data0,{{"""", type text}, {""2"", type text}, {""3"", type text}, {""4"", type any}, {""B's"", Int64.Type}, {""1"", Int64.Type}, {""X"", Int64.Type}, {""22"", Int64.Type}," & _
        " {""5"", type text}, {""6"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Modificato tipo"""
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
        "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Table 0 (3)"";Extended Properties=""""" _
        , Destination:=Range("$A$1")).QueryTable
        .CommandType = xlCmdSql
        .CommandText = Array("SELECT * FROM [Table 0 (3)]")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .ListObject.DisplayName = "Table_0__3"
        .Refresh BackgroundQuery:=False
    End With
    Application.CommandBars("Queries and Connections").Visible = False
End Sub
rombotuono
Utente Senior
 
Post: 112
Iscritto il: 09/11/18 17:27

Re: problema con macro

Postdi Anthony47 » 01/11/21 16:05

ho provato con il registratore macro ad importare la tabella che mi interessa su windows 11 ma non mi permette di caricarla nuovamente perchè la querry è già presente con lo stesso nome.
visto che ho bisogno di importare nello stesso range tabelle con link diversi
grazie
Non sono convinto di aver capito bene quale sia quindi la richiesta; supponiamo che sia "come faccio a creare una query con un nome che sia gia' presente".
In questo caso potremmo cancellare la query prima di reinserirla, aggiungendo questo blocco in questa posizione:
Codice: Seleziona tutto
'... (altre istruzioni)
    Application.CutCopyMode = False
'AGGIUNGERE...
On Error Resume Next
    ActiveSheet.ListObjects(1).Delete
    ActiveWorkbook.Queries("Table 0 (3)").Delete
On Error GoTo 0
'...AGGIUNTO
    ActiveWorkbook.Queries.Add Name:="Table 0 (3)", Formula:= _
        "let" & Chr(13) & "" & Chr(10) & "    Origine = Web.Page(Web.Contents(""https://www.betexplorer.com/soccer/argentina/primera-nacional/""))," & Chr(13) & "" & Chr(10) & "    Data0 = Origine{0}[Data]," & Chr(13) & "" & Chr(10) & "    #""Modificato tipo"" = Table.TransformColumnTypes(Data0,{{"""", type text}, {""2"", type text}, {""3"", type text}, {""4"", type any}, {""B's"", Int64.Type}, {""1"", Int64.Type}, {""X"", Int64.Type}, {""22"", Int64.Type}," & _
        " {""5"", type text}, {""6"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Modificato tipo"""
'... (altre istruzioni)

Se invece la necessità e' diversa allora spiega piu' in dettaglio

Ciao
Avatar utente
Anthony47
Moderatore
 
Post: 19213
Iscritto il: 21/03/06 16:03
Località: Ivrea

Re: problema con macro

Postdi rombotuono » 01/11/21 18:04

ciao
vorrei importare da questo link
https://www.betexplorer.com/soccer/arge ... ofesional/
questa tabella
Estudiantes L.P. - River Plate 17 4.25 3.44 1.82 FIN 1:1
Patronato - Colon Santa FE 17 2.74 3.03 2.65 Today 23:00
Central Cordoba - Aldosivi 17 1.81 3.55 4.17 Tomorrow 01:15
Defensa y Justicia - Rosario Central 16 1.75 3.51 4.41 05.11. 23:00
Lanus - Estudiantes L.P. 16 2.23 3.32 3.01 06.11. 01:15
Colon Santa FE - Platense 15 1.97 3.26 3.70 06.11. 17:30
Godoy Cruz - Talleres Cordoba 16 2.48 3.15 2.76 06.11. 19:45
Independiente - Arsenal Sarandi 16 1.75 3.43 4.56 06.11. 22:00
Atl. Tucuman - Racing Club 16 2.23 3.30 3.01 07.11. 00:15
Sarmiento Junin - Central Cordoba 14 1.98 3.32 3.60 07.11. 17:30
Gimnasia L.P. - Banfield 15 2.39 3.11 2.91 07.11. 19:45
Velez Sarsfield - San Lorenzo 15 1.56 3.73 5.77 07.11. 22:00
River Plate - Patronato 14 1.33 4.74 8.62 08.11. 00:15

perchè con la macro che utilizzavo non funziona più dopo aver aggiornato il pc a windows 11
le sto provando tutte ma senza alcun risultato.
grazie
rombotuono
Utente Senior
 
Post: 112
Iscritto il: 09/11/18 17:27

Re: problema con macro

Postdi rombotuono » 01/11/21 22:58

ciao
per quanto riguarda la modifica della query si funziona se lascio lo stesso link https://www.betexplorer.com/soccer/arge ... -nacional/
perchè è presente nel codice.
se cambio link per es. https://www.betexplorer.com/soccer/brazil/serie-a/ purtroppo non funziona
avrei bisogno che il codice legga il link presente cella m1 del foglio pp
non so se questo sia fattibile
grazie
rombotuono
Utente Senior
 
Post: 112
Iscritto il: 09/11/18 17:27

Re: problema con macro

Postdi Anthony47 » 02/11/21 10:43

La query che hai pubblicato e' del tipo SQLquery, io non ho nessuna competenza sul linguaggio SQL quindi non so intervenire sulla query per determinare le informazioni da estrarre; mi ero limitato ad aggiungere le istruzioni che rimuovono una query precedente prima di inserirne una nuova.
Se il problema e' fargli prendere l'url da M1 allora bisogna modificare l'istruzione ActiveWorkbook.Queries.Add. Io farei anche le modifiche per cancellare le query esistenti prima di inserire la nuova, e per evitare di inserire nuove colonne per ogni query che aggiungi.
Il codice diventerebbe:
Codice: Seleziona tutto
Sub sssssssssssssss()
'
' sssssssssssssss Macro
    Sheets("pp").Select
    Range("M1").Select
    Selection.Copy
    Application.CutCopyMode = False
'AGGIUNGERE...
On Error Resume Next
    ActiveSheet.ListObjects(1).Delete
On Error GoTo 0
For Each mq In ActiveWorkbook.Queries
    mq.Delete
Next mq
For Each wq In ActiveSheet.QueryTables
    wq.Delete
Next wq
'...AGGIUNTO
    ActiveWorkbook.Queries.Add Name:="Table 0 (3)", Formula:= _
        "let" & Chr(13) & "" & Chr(10) & "    Origine = Web.Page(Web.Contents(""" & Range("M1").Value & """))," & Chr(13) & "" & Chr(10) & "    Data0 = Origine{0}[Data]," & Chr(13) & "" & Chr(10) & "    #""Modificato tipo"" = Table.TransformColumnTypes(Data0,{{"""", type text}, {""2"", type text}, {""3"", type text}, {""4"", type any}, {""B's"", Int64.Type}, {""1"", Int64.Type}, {""X"", Int64.Type}, {""22"", Int64.Type}," & _
        " {""5"", type text}, {""6"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Modificato tipo"""
       
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
        "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Table 0 (3)"";Extended Properties=""""" _
        , Destination:=Range("$A$1")).QueryTable
        .CommandType = xlCmdSql
        .CommandText = Array("SELECT * FROM [Table 0 (3)]")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlOverwriteCells   'xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .ListObject.DisplayName = "Table_0__3"
        .Refresh BackgroundQuery:=False
    End With
    Application.CommandBars("Queries and Connections").Visible = False
End Sub


Ciao
Avatar utente
Anthony47
Moderatore
 
Post: 19213
Iscritto il: 21/03/06 16:03
Località: Ivrea

Re: problema con macro

Postdi rombotuono » 02/11/21 17:46

grazie
risolto ripristinando windows 10
rombotuono
Utente Senior
 
Post: 112
Iscritto il: 09/11/18 17:27


Torna a Applicazioni Office Windows


Topic correlati a "problema con macro":


Chi c’è in linea

Visitano il forum: Nessuno e 55 ospiti