Passing a boolean value to the Workbook_Open event

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
437
Good day,

I have two spreadsheets with the first opening the second via a pretty standard method (Application.FileDialog(msoFileDialogFilePicker))

Spreadsheet #1
VBA Code:
Set fd = Application.FileDialog(msoFileDialogFilePicker)
bExit_ = False

With fd
    .Filters.Clear
    .ButtonName = "Load Incident"
    .Filters.Add "Excel Files", "*.xls?, *.csv", 1
    .Title = "Choose your incident report"
    .AllowMultiSelect = False
    .InitialFileName = sPath
    If .Show = True Then
        For i = 1 To .SelectedItems.Count
            sFile = .SelectedItems(i)
           
            Set mWb = Workbooks.Open(sFile)
        Next i
    Else
        bExit_ = True
        Exit Sub
    End If
End With

sFile represents the 2nd spreadsheet. On the 2nd spreadsheet, there is small Workbook_Open routine where a variable bAdmin_ is set to False by default. I'd like this to be false when someone opens up the 2nd spreadsheet directly but set to true if the 1st spreadsheet opens up the 2nd.

Spreadsheet #2

VBA Code:
Public Sub Workbook_Open()

bAdmin_ = False
Call WorkbookSetup

ThisWorkbook.Worksheets("Form").Activate
ThisWorkbook.Worksheets("Form").Range("C20").Select

End Sub


Any thoughts?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
You can't pass arguments to that event. I'd suggest you use a separate routine that is called from Workbook_Open and takes an optional argument (defaulting to False). Your other code can then disable events and call that routine using application.run
 
Upvote 0
You disable events using:

Code:
application.enableevents = false

then open the workbook and run its macro using:

Code:
application.run “‘“ & mwb.name & “‘!macro_name”, true
 
Upvote 0
Solution

Forum statistics

Threads
1,214,944
Messages
6,122,392
Members
449,081
Latest member
JAMES KECULAH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top