我要做的是在Auto Update& amp;更新之间传递一个interger参数。更新,以便每次For RowNumber上升一,它将该值存储在自动更新中,然后关闭并重新打开更新,然后继续计算它停止的RowNumber。这就是我到目前为止所拥有的。如何让Panel.xls打开和关闭?
Public RowNumber As Integer
Public LoopCount As Integer
Sub auto_open()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.PrintCommunication = False
Dim PanelFilePath As String
Dim PanelFileName As String
Dim PanelLocation As String
Dim PanelWB As Workbook
PanelFilePath = "D:\umc\UMC Production Files\Automation Files\"
PanelFileName = "Panel.xls"
PanelLocation = PanelFilePath & Dir$(PanelFilePath & PanelFileName)
RowNumber = 0
For LoopCount = 0 To 7
If LoopCount < 7 Then
Set PanelWB = Workbooks.Open(Filename:=PanelLocation, UpdateLinks:=3)
PanelWB.RunAutoMacros Which:=xlAutoOpen
Application.Run "Panel.xls!Update"
PanelWB.Close
End If
Next LoopCount
Call Shell("D:\umc\UMC Production Files\Automation Files\Auto.bat", vbNormalFocus)
Application.Quit
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.PrintCommunication = True
End Sub
Function Update(LoopCount As Integer)
getRowNumber = LoopCount
End Function
Panel.xls!更新
Sub Update()
Dim AutoUpdateTargetFile As String
Dim AutoUpdateWB As Workbook
For RowNumber = 1 To (Range("AutoUpdate.File").Rows.Count - 1)
If (Range("AutoUpdate.File").Rows(RowNumber) <> "") Then
AutoUpdateTargetFile = Range("Sys.Path") & Range("Client.Path").Rows(RowNumber) & Range("AutoUpdate.Path ").Rows(RowNumber) & Range("AutoUpdate.File").Rows(RowNumber)
Set AutoUpdateWB = Workbooks.Open(Filename:=AutoUpdateTargetFile, UpdateLinks:=3)
AutoUpdateWB.RunAutoMacros Which:=xlAutoOpen
Application.Run "Auto_Update.xls!Flat"
AutoUpdateWB.Close
End If
Next RowNumber
End Sub
答案 0 :(得分:1)
1)。您已声明Public var:
Public RowNumber As Integer
所以删除Sub
中相同var的本地声明Dim RowNumber As Integer 'remove
2)。关于如何传递参数&#34;的第二个问题,请参考以下示例,演示将参数传递给Sub ByVal
或ByRef
的两个选项:
Sub Example(ByVal Num1 As Integer, ByRef Num2 As Integer)
'code
End Sub
希望这会有所帮助。最好的问候,