make an object visible to others

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,559
Hi
I got error message running the second sub. I thought x would be visible to consequence subs but I guess that is not the case. How can I make x visible to all other subs? Thank you.


Sub workbooksoepn()
Dim x As Workbook
Set x = Workbooks.Open("C:\Users\userme\Desktop\abc.xlsx")
End Sub


Sub protecttheopenfile()
x.Protect
End Sub
 

Some videos you may like

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,736
Office Version
2010
Platform
Windows
Code:
Option Explicit

Sub workbooksoepn()
  Dim x             As Workbook
  
  Set x = Workbooks.Open("C:\Users\userme\Desktop\abc.xlsx")
  protecttheopenfile x
End Sub

Sub protecttheopenfile(x As Workbook)
  x.Protect
End Sub
It would be a kindness if you would use CODE tags.
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,089,857
Messages
5,410,810
Members
403,330
Latest member
roxmasters2020

This Week's Hot Topics

Top