我正在尝试从其他xls创建vba导入表。我希望主xlsm的用户有权更改单元格中导入文件的位置。(不编辑vba)
我使用宏记录器来获取此文件,并且此代码中有某些内容无法正常工作。我猜这里:(File.Contents( import_path ), null, true)
'Source importfile
import_path = Sheets("dagsbud").Range("q14")
ActiveWorkbook.Queries.Add Name:="page", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Kilde = Excel.Workbook(File.Contents( import_path ), null, true)," & Chr(13) & "" & Chr(10) & " page_Sheet = Kilde{[Item=""page"",Kind=""Sheet""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Endret type"" = Table.TransformColumnTypes(page_Sheet,{{""Column1"", Int64.Type}, {""Column2"", type any}, {""Column3"", type" & _
" any}, {""Column4"", type any}, {""Column5"", type any}, {""Column6"", type any}, {""Column7"", type any}, {""Column8"", type any}, {""Column9"", type any}, {""Column10"", type any}, {""Column11"", type any}, {""Column12"", type any}, {""Column13"", type any}, {""Column14"", type any}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Endret type"""
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=page;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [page]")
.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"
.Refresh BackgroundQuery:=False
End With
End Sub