0

What I am trying to do is pass an interger argument between Auto Update & Update so that each time For RowNumber goes up by one that it stores that value in Auto Update and then closes and reopens Update which then continues counting RowNumber where it left off. This is what I have so far. How do I get the Panel.xls to open and close?

    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!Update

 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
5
  • 1
    Have you considered using a Global variable? Commented Dec 17, 2014 at 16:44
  • So I would make RowNumber a Global variable? Commented Dec 17, 2014 at 16:49
  • 1
    Sorry, I meant a Public variable. You could make RowNumber a Public variable and then reference it in your other workbook. See this example. Commented Dec 17, 2014 at 17:00
  • Thanks! Now I just need to figure out how to set up the function. =) Commented Dec 17, 2014 at 17:08
  • The question is a bit misleading, because the core issue is not about passing the integer argument, but proper use of Public var. Best regards, Commented Dec 17, 2014 at 18:04

1 Answer 1

1

1). You have declared Public var:

Public RowNumber As Integer

so remove the local declaration of the same var in Sub

Dim RowNumber As Integer 'remove

2). Regarding your second issue on 'how to pass the argument", refer to the following example demonstrating two options of passing arguments to Sub ByVal or ByRef:

 Sub Example(ByVal Num1 As Integer, ByRef Num2 As Integer)
 'code
 End Sub

Hope this will help. Best regards,

Sign up to request clarification or add additional context in comments.

1 Comment

Fixed that but my issue is still how to pass the argument.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.