我的 Access 数据库以 xls 格式导出报告,需要进一步修改(对列进行一些手动调整等 + 从前一天的报告中查找一些评论)。
这是我到目前为止创建的部分代码:
Option Compare Database
Function Adjustment()
' First I want to prompt user to select the report from previous day*
Dim f As Object
Dim strFile As String
Dim strFolder As String
Dim varItem As Variant
Set f = Application.FileDialog(3)
f.AllowMultiSelect = True
If f.Show Then
For Each varItem In f.SelectedItems
strFile = Dir(varItem)
MsgBox (strFile)
Next
End If
Set f = Nothing
' here my Access database opens current report that has been exported
Dim xl As Object
Set xl = CreateObject("Excel.Application")
xl.Workbooks.Open ("I:\Temp\reports.xlsx")
xl.Visible = True
' in currently open report, I want fill cell I2 and J2 with VLOOKUP function referencing to previously selected file
Range("I2").FormulaR1C1 = "=VLOOKUP(RC7,'[" & strFile & "]SheetXY'!C7:C12,3,0)"
Range("J2").FormulaR1C1 = "=VLOOKUP(RC7,'[" & strFile & "]SheetXY!C7:C12,4,0)"
End function
问题:每次都提示我选择文件,当公式被填入 I2 和 J2 时,那么我怎样才能禁用它并只保留一次访问引用 strFile 的权限?
问题:到目前为止,被引用的工作簿中的每个第一张表都称为 SheeyXY,但是如果我还想引用不同的工作表怎么办(假设总是工作簿中的第一张表,无论其名称是什么)。