目的是实现输入日期之后能查询对应日期文件夹内的表格,但是我试着写出来的一直提示错误[Expressiong Error]无法识别名称”Source“,我检查看建立的查询里面路径没有随a定位到指定日期,是我使用错误还是查询中不能添加变量啊?可以怎么解决?谢谢大家
Dim a As String, b As Date, c As String
a = InputBox("输入数据日期:")
b = a
c = MsgBox("数据是否是TR返回的", vbYesNo)
Application.ScreenUpdating = False
If c = vbYes Then
a = a & "REV"
End If
'Comfirm the Date
Dim wb As Workbook
Set wb = Workbooks.Add
ActiveWorkbook.Queries.Add Name:="PCSData", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " 源 = Folder.Files(""E:\Progress\6.Progress Control Sheet\"" & a "")," & Chr(13) & "" & Chr(10) & " (中间是一系列PQ中的操作,是录制了直接粘贴的)
Sheets.Add After:=ActiveSheet
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=PCSData;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [PCSData]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "PCSData"
.Refresh BackgroundQuery:=False
End With
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
Dim a As String, b As Date, c As String
a = InputBox("输入数据日期:")
b = a
c = MsgBox("数据是否是TR返回的", vbYesNo)
Application.ScreenUpdating = False
If c = vbYes Then
a = a & "REV"
End If
'Comfirm the Date
Dim wb As Workbook
Set wb = Workbooks.Add
ActiveWorkbook.Queries.Add Name:="PCSData", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " 源 = Folder.Files(""E:\Progress\6.Progress Control Sheet\"" & a "")," & Chr(13) & "" & Chr(10) & " (中间是一系列PQ中的操作,是录制了直接粘贴的)
Sheets.Add After:=ActiveSheet
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=PCSData;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [PCSData]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "PCSData"
.Refresh BackgroundQuery:=False
End With
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False