Public Variable Declaration Problem

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,570
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have variable ws_form declared publicly as a worksheets at the workbook level of my code.
In the workbook open event, I set the variable:
Code:
Private Sub Workbook_Open()
    Set wb_demo1 = Workbooks("demo1.xlsm")
    Set ws_form = wb_demo1.Worksheets("Form")
End Sub

At the end of my workbook open code, if I check to see if the variable has been declared properly, ws_form.name does return a result of "Form"

I have code in my userform button that refers to actions needed on worksheet "Form".

Code:
Private Sub btn_proceed_Click()
    Unload Me
    With ws_form
        .Unprotect
        .Range("O3").Value = emplnum
        .Range("O4").Value = eqtnum
        .Activate
        .Protect
    End With
End Sub

At this point, it appears as though I have lost the association of ws_form with worksheets("Form"). If I test ws_form.name, I get an Object required error. If I've declared ws_form globally through the PUblic declaration, shouldn't it be retained throughout the project? Any idea why I Have lost it?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Global variables need to be declared in a standard module.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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