我在Excel中使用宏記錄器來記錄我需要自動化的一系列任務。這些任務發生在兩個不同的Excel電子表格之間。我相信宏在當前工作表上執行代碼,但現在第二張表是硬編碼的。我如何提示用戶選擇一個Excel工作表來引用?VBA提示用戶選擇Excel表格
那將會有宏工作簿是MasterHardwareDB
&需要用戶的輸入被替換爲Computer&DeploymentInfo_06_23_15_v3.xlsx
我研究了FileDialog對象,但我不知道怎麼在這裏整合文件。
Sub AutomateCompare()
'
' AutomateCompare Macro
'
ActiveCell.Select
ActiveCell.FormulaR1C1 = _
"=INDEX('Computer&DeploymentInfo_06_23_15_v3.xlsx'!Table1[scheduleddate],MATCH([ @HostName],'Computer&DeploymentInfo_06_23_15_v3.xlsx'!Table1[computername],0))"
ActiveCell.Offset(1, 0).Range("MasterHardwareDB[[#Headers],[Name]]").Select
ActiveCell.FormulaR1C1 = _
"=INDEX('Computer&DeploymentInfo_06_23_15_v3.xlsx'!Table1[scheduleddate],MATCH([@HostName],'Computer&DeploymentInfo_06_23_15_v3.xlsx'!Table1[computername],0))"
ActiveCell.Offset(1, 0).Range("MasterHardwareDB[[#Headers],[Name]]").Select
ActiveWindow.SmallScroll ToRight:=-1
ActiveCell.Offset(-2, 1).Range("MasterHardwareDB[[#Headers],[Name]]").Select
ActiveCell.FormulaR1C1 = _
"=INDEX('Computer&DeploymentInfo_06_23_15_v3.xlsx'!Table1[forecastdate],MATCH([@HostName],'Computer&DeploymentInfo_06_23_15_v3.xlsx'!Table1[computername],0))"
ActiveWindow.SmallScroll ToRight:=1
ActiveCell.Offset(1, 0).Range("MasterHardwareDB[[#Headers],[Name]]").Select
ActiveWindow.SmallScroll ToRight:=-7
ActiveSheet.ListObjects("MasterHardwareDB").Range.AutoFilter Field:=9, _
Criteria1:="FALSE"
ActiveWindow.SmallScroll ToRight:=1
ActiveCell.Offset(4169, -4).Range("MasterHardwareDB[[#Headers],[Name]:[EmpID]]") _
.Select
ActiveCell.Offset(521, 1).Range("MasterHardwareDB[[#Headers],[Name]]").Select
ActiveWindow.SmallScroll ToRight:=-7
ActiveSheet.ListObjects("MasterHardwareDB").Range.AutoFilter Field:=5, _
Criteria1:="=Scheduled", Operator:=xlOr, Criteria2:="=To Be Scheduled"
ActiveCell.Offset(87, -8).Range("MasterHardwareDB[[#Headers],[Name]]").Select
ActiveWindow.SmallScroll ToRight:=8
End Sub
它看起來像[此線索](代碼http://stackoverflow.com/questions/5600533/how-do-i-prompt-用戶選擇文件和工作表時使用宏到impor)可能能夠幫助你。看看第一個答案,那會讓你開始。你熟悉VBA嗎? – BruceWayne