bobaol
Board Regular
- Joined
- Jun 3, 2002
- Messages
- 227
- Office Version
- 365
- 2003 or older
- Platform
- Windows
Hello, how do I add the source column when I am opening only one file? Any help would be greatly appreciated. thanks in advance. Here is my code below.
Sub Macro1()
ActiveWorkbook.Queries.Add Name:="Table023 (Page 6)", Formula:="let" & Chr(13) & "" & Chr(10) & " Source = Pdf.Tables(File.Contents(""C:\Temp2\6489.pdf""), [Implementation=""1.3""])," & Chr(13) & "" & Chr(10) & " Table023 = Source{[Id=""Table023""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Table023,{{""Column1"", type text}, {""Column2"", type text}, {""Column3"", type text}, {""Column4"", type text}, {""Column5"", type text}})" & Chr(13) & "" & Chr(10) & "" & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Table023 (Page 6)"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Table023 (Page 6)]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table023__Page_6"
.Refresh BackgroundQuery:=False
End With
ActiveWorkbook.SaveAs Filename:="C:\Temp2\PQ_T2.xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End Sub
Sub Macro1()
ActiveWorkbook.Queries.Add Name:="Table023 (Page 6)", Formula:="let" & Chr(13) & "" & Chr(10) & " Source = Pdf.Tables(File.Contents(""C:\Temp2\6489.pdf""), [Implementation=""1.3""])," & Chr(13) & "" & Chr(10) & " Table023 = Source{[Id=""Table023""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Table023,{{""Column1"", type text}, {""Column2"", type text}, {""Column3"", type text}, {""Column4"", type text}, {""Column5"", type text}})" & Chr(13) & "" & Chr(10) & "" & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Table023 (Page 6)"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Table023 (Page 6)]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table023__Page_6"
.Refresh BackgroundQuery:=False
End With
ActiveWorkbook.SaveAs Filename:="C:\Temp2\PQ_T2.xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End Sub