我有两张表,我需要刷新值(函数VLOOKUP)从source.xlsm到update.xlsm ON BACKGROUND by VBA(只有手动刷新按钮和指定的宏 - 我不想在Excel中使用更新按钮选项)。
我找到了两个完成此任务的代码,但是,在完成任务时,source.xlsm总是会弹出一秒钟。我希望在屏幕上看不到源文件的情况下完成任务。
有什么想法吗?
Sub Read_External_Sheet()
'''''Define Object for Target Workbook
Dim Target_Workbook As Workbook
Dim Source_Workbook As Workbook
Dim Target_Path As String
'''''Assign the Workbook File Name along with its Path
'''''Change path of the Target File name
Target_Path = "D:\Source.xlsm"
Set Target_Workbook = Workbooks.Open(Target_Path)
Set Source_Workbook = ThisWorkbook
'''''With Target_Workbook object now, it is possible to pull any data from it
'''''Read Data from Target File
Target_Data = Target_Workbook.Sheets(1).Cells(1, 1)
DoEvents
Source_Workbook.Sheets(1).Cells(1, 1) = Target_Data
DoEvents
'''''Update Target File
Source_data = Source_Workbook.Sheets(1).Cells(3, 1)
DoEvents
Target_Workbook.Sheets(1).Cells(2, 1) = Source_data
DoEvents
'''''Close Target Workbook
Target_Workbook.Close False
'''''Process Completed
MsgBox "SHEET UPDATED"
End Sub
Sub Read_External_Sheet_2()
Dim FName As Workbook
With Application
.EnableEvents = False
Set FName = .Workbooks.Open("D:\Source.xlsm", False)
mybook = FName.Name
With FName
.RefreshAll
.Close True 'save file
End With
.EnableEvents = True
End With
msg = MsgBox(mybook & " Refreshed")
End Sub