funzione accodare query Power Query

Anonimo
2022-05-28T11:22:42+00:00

buon giorno, mi presento qui per chiedere un vostro aiuto in un problemino che ho con vba su excel 365 professional. spiego brevemente, devo importare in una cartella delle tabelle da uno o due file pdf. il problema che ho, consiste nel fatto che i pdf hanno numeri di pagine variabili, da 5 sino anche 500. quello che riesco a fare è caricare i file i query, e per unirli ho dovuto ripetere la formula accoda in base a quante pagine ci sono. non riesco a dirgli di capire da solo quante sono le pagine e di accodarle....

Sub Macro_carica_accorpa_1()

'

Dim wbk3 As Workbook

Dim Indirizzo As String

Dim Indirizzo1 As String

Dim COUNT As Integer

Dim COUNT1 As Integer

Dim DATA As String

Dim sh As Worksheet

Dim ListObj As ListObject

Dim pq As Object

Application.ScreenUpdating = False

Application.DisplayAlerts = False

Indirizzo = Range("u1").Value

PageN = Range("w1").Value

Pages = Range("w2").Value

Indirizzo1 = Range("u2").Value

PageT = Range("w3").Value

Do

COUNT = COUNT + 1 

PageRif = "Page" & Format(COUNT, "000") 

ActiveWorkbook.Queries.Add Name:="Page" & Format(COUNT, "000"), Formula:= \_ 

    "let" & Chr(13) & "" & Chr(10) & "    Origine = Pdf.Tables(File.Contents(""" & Indirizzo & """), [Implementation=""1.3""])," & Chr(13) & "" & Chr(10) & "    Page1 = Origine{[Id=""" & PageRif & """]}[Data]," & Chr(13) & "" & Chr(10) & "    #""Modificato tipo"" = Table.TransformColumnTypes(Page1,{{""Column1"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " " & \_ 

    "   #""Modificato tipo""" 

Loop While COUNT < PageN

If Pages = 0 Then

Else

Do

COUNT = COUNT + 1 

COUNT1 = COUNT1 + 1 

PageRif = "Page" & Format(COUNT1, "000") 

ActiveWorkbook.Queries.Add Name:="Page" & Format(COUNT, "000"), Formula:= \_ 

    "let" & Chr(13) & "" & Chr(10) & "    Origine = Pdf.Tables(File.Contents(""" & Indirizzo1 & """), [Implementation=""1.3""])," & Chr(13) & "" & Chr(10) & "    Page1 = Origine{[Id=""" & PageRif & """]}[Data]," & Chr(13) & "" & Chr(10) & "    #""Modificato tipo"" = Table.TransformColumnTypes(Page1,{{""Column1"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " " & \_ 

    "   #""Modificato tipo""" 

Loop While COUNT < PageT

End If

If Sheets("Comandi").Range("w3").Value = 1 Then

Sheets("Comandi").Range("w4").Value = 1

Else

End If 

If Sheets("Comandi").Range("w3").Value = 2 Then

ActiveWorkbook.Queries.Add Name:="Accoda1", Formula:= _

    "let" & Chr(13) & "" & Chr(10) & "    Origine = Table.Combine({Page001, Page002})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    Origine" 

 Sheets("Comandi").Range("w4").Value = 2 

Else 

End If 

If Sheets("Comandi").Range("w3").Value = 3 Then 

ActiveWorkbook.Queries.Add Name:="Accoda1", Formula:= _

    "let" & Chr(13) & "" & Chr(10) & "    Origine = Table.Combine({Page001, Page002, Page003})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    Origine" 

Sheets("Comandi").Range("w4").Value = 3 

Else 

End If 

If Sheets("Comandi").Range("w3").Value = 4 Then 

ActiveWorkbook.Queries.Add Name:="Accoda1", Formula:= _

    "let" & Chr(13) & "" & Chr(10) & "    Origine = Table.Combine({Page001, Page002, Page003, Page004})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    Origine" 

Sheets("Comandi").Range("w4").Value = 4 

Else 

End If 

If Sheets("Comandi").Range("w3").Value = 5 Then 

ActiveWorkbook.Queries.Add Name:="Accoda1", Formula:= _

    "let" & Chr(13) & "" & Chr(10) & "    Origine = Table.Combine({Page001, Page002, Page003, Page004, Page005})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    Origine" 

Sheets("Comandi").Range("w4").Value = 5 

Else 

End If 

If Sheets("Comandi").Range("w3").Value = 6 Then 

ActiveWorkbook.Queries.Add Name:="Accoda1", Formula:= _

    "let" & Chr(13) & "" & Chr(10) & "    Origine = Table.Combine({Page001, Page002, Page003, Page004, Page005, Page006})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    Origine" 

Sheets("Comandi").Range("w4").Value = 6 

Else 

End If 

If Sheets("Comandi").Range("w3").Value = 7 Then 

ActiveWorkbook.Queries.Add Name:="Accoda1", Formula:= _

    "let" & Chr(13) & "" & Chr(10) & "    Origine = Table.Combine({Page001, Page002, Page003, Page004, Page005, Page006, Page007})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    Origine" 

Sheets("Comandi").Range("w4").Value = 7 

Else 

End If

ecc...(io sono arrivato a scrivere sino a 70 con le possibilità di accodamento)

If Sheets("Comandi").Range("w4").Value = 1 Then

ActiveWorkbook.Worksheets.Add 

With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= \_ 

    "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=" & PageRif & ";Extended Properties=""""" \_ 

    , Destination:=Range("$A$1")).QueryTable 

    .CommandType = xlCmdSql 

    .CommandText = Array("SELECT \* FROM [Page" & Format(COUNT, "000") & "]") 

    .RowNumbers = False 

    .FillAdjacentFormulas = False 

    .PreserveFormatting = True 

    .RefreshOnFileOpen = False 

    .BackgroundQuery = True 

    .RefreshStyle = xlInsertDeleteCells 

    .SavePassword = False 

    .SaveData = True 

    .AdjustColumnWidth = True 

    .RefreshPeriod = 0 

    .PreserveColumnInfo = True 

    .ListObject.DisplayName = "Page" & Format(COUNT, "000") 

    .Refresh BackgroundQuery:=False 

    Application.DisplayAlerts = False 

End With 

Else 

ActiveWorkbook.Worksheets.Add 

With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= \_ 

    "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Accoda1;Extended Properties=""""" \_ 

    , Destination:=Range("$A$1")).QueryTable 

    .CommandType = xlCmdSql 

    .CommandText = Array("SELECT \* FROM [Accoda1]") 

    .RowNumbers = False 

    .FillAdjacentFormulas = False 

    .PreserveFormatting = True 

    .RefreshOnFileOpen = False 

    .BackgroundQuery = True 

    .RefreshStyle = xlInsertDeleteCells 

    .SavePassword = False 

    .SaveData = True 

    .AdjustColumnWidth = True 

    .RefreshPeriod = 0 

    .PreserveColumnInfo = True 

    .ListObject.DisplayName = "Accoda1" 

    .Refresh BackgroundQuery:=False 

End With 

End If 

End Sub 

la formula funziona(sino alle 70 pagine fa egregiamente il suo lavoro) , ma siccome posso avere il pdf che può arrivare sino a 500 pagine e oltre, o trovo un modo per caricare tutto il pdf in una unica tabella(visto che le pagine hanno la stessa intestazione) o un modo per automatizzare magari con do e loop la parte che riguarda l'accodamento....

ActiveWorkbook.Queries.Add Name:="Accoda1", Formula:= _

    "let" & Chr(13) & "" & Chr(10) & "    Origine = Table.Combine({Page001, Page002, Page003, Page004, Page005})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    Origine" 

ma non riesco a capire come dargli i riferimenti.

vi ringrazio per qualsiasi mano che mi possiate dare.

Microsoft 365 e Office | Excel | Per il lavoro | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento

6 risposte

Ordina per: Più utili
  1. Anonimo
    2022-05-31T10:34:23+00:00

    scusa, ma non riesco ad integrare la tua con la mia.... perchè la tua è settata su una sola colonna, e non riesco a sbloccarla(il pezzo che ho io si adatta in automatico al numero di colonne, che nel mio caso possono essere 16 o 18)... non sono bravo con il vba(credo si capisca)... :-(

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2022-05-30T06:44:04+00:00

    Ciao Fabio ,

    Potresti scaricare il file Fabio.zip che include sia il mio file di test che il mio file pdf.

    ===

    Regards,

    Norman

    Immagine

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2022-05-30T06:40:29+00:00

    grazie, oggi provo i codici... specifico che il pdf ha dalle 16 alle 18 colonne, ma a volte potrebbe creare un problema nel caricamento se le specifico tutte. ho notato che se indico solo la prima, in automatico si carica tutte le altre senza crearmi problemi.....

    La risposta è stata utile?

    0 commenti Nessun commento
  4. Anonimo
    2022-05-30T06:01:31+00:00

    Ciao Fabio,

    Visto che sembra che il tuo file pdf contenga una sola colonna, al contrario del mio file prova originale, che conteneva 3 colonne, prova invece la versione seguente, in cui ho anche approfittato per rendere il codice more robusto e resistente:

    '========>>

    Option Explicit

    '-------->>

    Public Sub Combine_Data2()

    Dim WB As Workbook 
    
    Dim SH As Worksheet 
    

    Const sPercorso As String = "C:\Users\Fabio)\Documents\myPDF.pdf" '<<=== Modifica

    Const sQuery\_Name As String = **"Pippo"               '&lt;&lt;=== Modifica** 
    
    Const sFoglio\_Pdf As String = **"PDF"                 '&lt;&lt;=== Modifica** 
    
    Const sDoubleQuote As String = """" 
    
    Set WB = ThisWorkbook 
    
    With WB 
    
        If SheetExists(sFoglio\_Pdf) Then 
    
            Set SH = .Sheets(sFoglio\_Pdf) 
    
            SH.UsedRange.ClearContents 
    
        Else 
    
            Set SH = .Sheets.Add(Before:=.Sheets(1)) 
    
            SH.Name = sFoglio\_Pdf 
    
        End If 
    
        On Error Resume Next 
    
        .Queries(sQuery\_Name).Delete 
    
        On Error GoTo 0 
    
        .Queries.Add Name:=sQuery\_Name, Formula:= \_ 
    
            "let" & Chr(13) & "" & Chr(10) & "    Source = Pdf.Tables(File.Contents(" & sDoubleQuote & sPercorso & sDoubleQuote & "), [Implementation=""1.3""])," & Chr(13) & "" & Chr(10) & "    #""Filtered Rows"" = Table.SelectRows(Source, each ([Kind] = ""Page""))," & Chr(13) & "" & Chr(10) & "    #""Expanded {0}"" = Table.ExpandTableColumn(#""Filtered Rows"", ""Data"", {""Column1""}, {""Data.Column1""})," & Chr(13) & "" & Chr(10) & "    #""Removed Other Colum" & \_ 
    
            "ns"" = Table.SelectColumns(#""Expanded {0}"",{""Data.Column1""})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Removed Other Columns""" 
    
    End With 
    
    With SH.ListObjects.Add(SourceType:=0, Source:= \_ 
    
        "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=" & sQuery\_Name & ";Extended Properties=""""" \_ 
    
        , Destination:=Range("$A$1")).QueryTable 
    
        .CommandType = xlCmdSql 
    
        .CommandText = Array("SELECT \* FROM [" & sQuery\_Name & "]") 
    
        .RowNumbers = False 
    
        .FillAdjacentFormulas = False 
    
        .PreserveFormatting = True 
    
        .RefreshOnFileOpen = False 
    
        .BackgroundQuery = True 
    
        .RefreshStyle = xlInsertDeleteCells 
    
        .SavePassword = False 
    
        .SaveData = True 
    
        .AdjustColumnWidth = True 
    
        .RefreshPeriod = 0 
    
        .PreserveColumnInfo = True 
    
        .ListObject.DisplayName = sQuery\_Name 
    
        .Refresh BackgroundQuery:=False 
    
    End With 
    

    End Sub

    '--------->>

    Public Function SheetExists(sSheetName As String, _

    Optional ByVal WB As Workbook) As Boolean 
    
    On Error Resume Next 
    
    If WB Is Nothing Then 
    
        Set WB = ThisWorkbook 
    
    End If 
    
    SheetExists = CBool(Len(WB.Sheets(sSheetName).Name)) 
    

    End Function

    '<<========

    ===

    Regards,

    Norman

    Immagine

    La risposta è stata utile?

    0 commenti Nessun commento
  5. Anonimo
    2022-05-29T22:32:23+00:00

    Ciao Fabio,

    mi presento qui per chiedere un vostro aiuto in un problemino che ho con vba su excel 365 professional. spiego brevemente, devo importare in una cartella delle tabelle da uno o due file pdf. il problema che ho, consiste nel fatto che i pdf hanno numeri di pagine variabili, da 5 sino anche 500. quello che riesco a fare è caricare i file i query, e per unirli ho dovuto ripetere la formula accoda in base a quante pagine ci sono. non riesco a dirgli di capire da solo quante sono le pagine e di accodarle....

    Sub Macro_carica_accorpa_1()

    '

    Dim wbk3 As Workbook

    Dim Indirizzo As String

    Dim Indirizzo1 As String

    Dim COUNT As Integer

    Dim COUNT1 As Integer

    Dim DATA As String

    Dim sh As Worksheet

    Dim ListObj As ListObject

    Dim pq As Object

    Application.ScreenUpdating = False

    Application.DisplayAlerts = False

    Indirizzo = Range("u1").Value

    PageN = Range("w1").Value

    Pages = Range("w2").Value

    Indirizzo1 = Range("u2").Value

    PageT = Range("w3").Value

    Do

    COUNT = COUNT + 1

    PageRif = "Page" & Format(COUNT, "000")

    ActiveWorkbook.Queries.Add Name:="Page" & Format(COUNT, "000"), Formula:= _

    "let" & Chr(13) & "" & Chr(10) & " Origine = Pdf.Tables(File.Contents(""" & Indirizzo & """), [Implementation=""1.3""])," & Chr(13) & "" & Chr(10) & " Page1 = Origine{[Id=""" & PageRif & """]}[Data]," & Chr(13) & "" & Chr(10) & " #""Modificato tipo"" = Table.TransformColumnTypes(Page1,{{""Column1"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " " & _

    " #""Modificato tipo"""

    Loop While COUNT < PageN

    If Pages = 0 Then

    Else

    Do

    COUNT = COUNT + 1

    COUNT1 = COUNT1 + 1

    PageRif = "Page" & Format(COUNT1, "000")

    ActiveWorkbook.Queries.Add Name:="Page" & Format(COUNT, "000"), Formula:= _

    "let" & Chr(13) & "" & Chr(10) & " Origine = Pdf.Tables(File.Contents(""" & Indirizzo1 & """), [Implementation=""1.3""])," & Chr(13) & "" & Chr(10) & " Page1 = Origine{[Id=""" & PageRif & """]}[Data]," & Chr(13) & "" & Chr(10) & " #""Modificato tipo"" = Table.TransformColumnTypes(Page1,{{""Column1"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " " & _

    " #""Modificato tipo"""

    Loop While COUNT < PageT

    End If

    If Sheets("Comandi").Range("w3").Value = 1 Then

    Sheets("Comandi").Range("w4").Value = 1

    Else

    End If

    If Sheets("Comandi").Range("w3").Value = 2 Then

    ActiveWorkbook.Queries.Add Name:="Accoda1", Formula:= _

    "let" & Chr(13) & "" & Chr(10) & " Origine = Table.Combine({Page001, Page002})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Origine"

    Sheets("Comandi").Range("w4").Value = 2

    Else

    End If

    If Sheets("Comandi").Range("w3").Value = 3 Then

    ActiveWorkbook.Queries.Add Name:="Accoda1", Formula:= _

    "let" & Chr(13) & "" & Chr(10) & " Origine = Table.Combine({Page001, Page002, Page003})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Origine"

    Sheets("Comandi").Range("w4").Value = 3

    Else

    End If

    If Sheets("Comandi").Range("w3").Value = 4 Then

    ActiveWorkbook.Queries.Add Name:="Accoda1", Formula:= _

    "let" & Chr(13) & "" & Chr(10) & " Origine = Table.Combine({Page001, Page002, Page003, Page004})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Origine"

    Sheets("Comandi").Range("w4").Value = 4

    Else

    End If

    If Sheets("Comandi").Range("w3").Value = 5 Then

    ActiveWorkbook.Queries.Add Name:="Accoda1", Formula:= _

    "let" & Chr(13) & "" & Chr(10) & " Origine = Table.Combine({Page001, Page002, Page003, Page004, Page005})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Origine"

    Sheets("Comandi").Range("w4").Value = 5

    Else

    End If

    If Sheets("Comandi").Range("w3").Value = 6 Then

    ActiveWorkbook.Queries.Add Name:="Accoda1", Formula:= _

    "let" & Chr(13) & "" & Chr(10) & " Origine = Table.Combine({Page001, Page002, Page003, Page004, Page005, Page006})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Origine"

    Sheets("Comandi").Range("w4").Value = 6

    Else

    End If

    If Sheets("Comandi").Range("w3").Value = 7 Then

    ActiveWorkbook.Queries.Add Name:="Accoda1", Formula:= _

    "let" & Chr(13) & "" & Chr(10) & " Origine = Table.Combine({Page001, Page002, Page003, Page004, Page005, Page006, Page007})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Origine"

    Sheets("Comandi").Range("w4").Value = 7

    Else

    End If

    ecc...(io sono arrivato a scrivere sino a 70 con le possibilità di accodamento)

    If Sheets("Comandi").Range("w4").Value = 1 Then

    ActiveWorkbook.Worksheets.Add

    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _

    "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=" & PageRif & ";Extended Properties=""""" _

    , Destination:=Range("$A$1")).QueryTable

    .CommandType = xlCmdSql

    .CommandText = Array("SELECT * FROM [Page" & Format(COUNT, "000") & "]")

    .RowNumbers = False

    .FillAdjacentFormulas = False

    .PreserveFormatting = True

    .RefreshOnFileOpen = False

    .BackgroundQuery = True

    .RefreshStyle = xlInsertDeleteCells

    .SavePassword = False

    .SaveData = True

    .AdjustColumnWidth = True

    .RefreshPeriod = 0

    .PreserveColumnInfo = True

    .ListObject.DisplayName = "Page" & Format(COUNT, "000")

    .Refresh BackgroundQuery:=False

    Application.DisplayAlerts = False

    End With

    Else

    ActiveWorkbook.Worksheets.Add

    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _

    "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Accoda1;Extended Properties=""""" _

    , Destination:=Range("$A$1")).QueryTable

    .CommandType = xlCmdSql

    .CommandText = Array("SELECT * FROM [Accoda1]")

    .RowNumbers = False

    .FillAdjacentFormulas = False

    .PreserveFormatting = True

    .RefreshOnFileOpen = False

    .BackgroundQuery = True

    .RefreshStyle = xlInsertDeleteCells

    .SavePassword = False

    .SaveData = True

    .AdjustColumnWidth = True

    .RefreshPeriod = 0

    .PreserveColumnInfo = True

    .ListObject.DisplayName = "Accoda1"

    .Refresh BackgroundQuery:=False

    End With

    End If

    End Sub

    la formula funziona(sino alle 70 pagine fa egregiamente il suo lavoro) , ma siccome posso avere il pdf che può arrivare sino a 500 pagine e oltre, o trovo un modo per caricare tutto il pdf in una unica tabella(visto che le pagine hanno la stessa intestazione) o un modo per automatizzare magari con do e loop la parte che riguarda l'accodamento....

    ActiveWorkbook.Queries.Add Name:="Accoda1", Formula:= _

    "let" & Chr(13) & "" & Chr(10) & " Origine = Table.Combine({Page001, Page002, Page003, Page004, Page005})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Origine"

    ma non riesco a capire come dargli i riferimenti.

    Se la tua intenzione fosse quella di utilizzare Power Query per creare una query basata su un file pdf con un numero di pagine indeterminato, forse prova qualcosa del genere:

    '========>>

    Option Explicit

    '-------->>

    Public Sub Combine_Data()

    Dim WB As Workbook

    Dim sPath As String

    Dim SH As Worksheet

    Const sPercorso As String = "C:\Users\Fabio)\Documents\myPDF.pdf" '<<=== Modifica

    Const sQuery_Name As String = "Pippo" '<<=== Modifica

    Const sDoubleQuote As String = """"

    Set WB = ThisWorkbook 
    
    With WB 
    
        .Queries.Add Name:=sQuery\_Name, Formula:= \_ 
    
            "let" & Chr(13) & "" & Chr(10) & "    Source = Pdf.Tables(File.Contents(" & sDoubleQuote & sPercorso & sDoubleQuote & "), [Implementation=""1.3""])," & Chr(13) & "" & Chr(10) & "    #""Filtered Rows"" = Table.SelectRows(Source, each ([Kind] = ""Page""))," & Chr(13) & "" & Chr(10) & "    #""Removed Other Columns"" = Table.SelectColumns(#""Filtered Rows"",{""Data""})," & Chr(13) & "" & Chr(10) & "    #""Expanded {0}"" = Table.ExpandTableColumn(#""Remov" & \_ 
    
            "ed Other Columns"", ""Data"", {""Column1"", ""Column2"", ""Column3"", ""Column4""}, {""Data.Column1"", ""Data.Column2"", ""Data.Column3"", ""Data.Column4""})," & Chr(13) & "" & Chr(10) & "    #""Promoted Headers"" = Table.PromoteHeaders(#""Expanded {0}"", [PromoteAllScalars=true])," & Chr(13) & "" & Chr(10) & "    #""Changed Type"" = Table.TransformColumnTypes(#""Promoted Headers"",{{""Name"", type text}, {""Country"", t" & \_ 
    
            "ype text}, {""Value"", Int64.Type}, {""Column4"", Int64.Type}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Changed Type""" 
    
        .Worksheets.Add 
    
    End With 
    
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= \_ 
    
        "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=" & sQuery\_Name & ";Extended Properties=""""" \_ 
    
        , Destination:=Range("$A$1")).QueryTable 
    
        .CommandType = xlCmdSql 
    
        .CommandText = Array("SELECT \* FROM [" & sQuery\_Name & "]") 
    
        .RowNumbers = False 
    
        .FillAdjacentFormulas = False 
    
        .PreserveFormatting = True 
    
        .RefreshOnFileOpen = False 
    
        .BackgroundQuery = True 
    
        .RefreshStyle = xlInsertDeleteCells 
    
        .SavePassword = False 
    
        .SaveData = True 
    
        .AdjustColumnWidth = True 
    
        .RefreshPeriod = 0 
    
        .PreserveColumnInfo = True 
    
        .ListObject.DisplayName = sQuery\_Name 
    
        .Refresh BackgroundQuery:=False 
    
    End With 
    

    End Sub

    '<<========

    ===

    Regards,

    Norman

    Immagine

    La risposta è stata utile?

    0 commenti Nessun commento