Running a macro when a workbook is opened

TheJay

Active Member
Joined
Nov 12, 2014
Messages
364
Office Version
  1. 2019
Platform
  1. Windows
I run code to protect cells, whilst allowing users to access certain features of Excel to view/sort data. I want to run two macros when the workbook is opened, to make sure any selections made in dropdown boxes are cleared.

I thought this would work, but it doesn't like the calls for macros.

VBA Code:
Private Sub Workbook_Open()
    Dim sh          As Worksheet
    For Each sh In Worksheets
        If sh.Name = "Property Numbering" Then
            sh.Protect UserInterFaceOnly:=True, AllowSorting:=True, AllowFiltering:=True
                    Call PRGEReset
                    Call PRGFReset
        Else
            sh.Protect UserInterFaceOnly:=True
        End If
    Next
End Sub

First module/macro:
VBA Code:
Sub PRGEReset()
    Range("C13").Select
    Selection.ClearContents
    Range("C13").Select
End Sub

Second module/macro:
VBA Code:
Sub PRGFReset()
    Range("C8").Select
    Selection.ClearContents
    Range("C8").Select
End Sub

Can someone please tell me how I get this working?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi,
try this update to your code & see if does what you want

Rich (BB code):
Private Sub Workbook_Open()
    Dim sh          As Worksheet
    For Each sh In Worksheets
        If sh.Name = "Property Numbering" Then
            sh.Protect UserInterFaceOnly:=True, AllowSorting:=True, AllowFiltering:=True
            sh.Range("C8,C13").ClearContents
        Else
            sh.Protect UserInterFaceOnly:=True
        End If
    Next
End Sub

Dave
 
Upvote 0
Solution
Thank you, so it's not possible to execute macros from Workbook_Open then?
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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