Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Confused, again! Object variable not set?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
davegb - 23 Jan 2006 23:14 GMT
This code is on the worksheet module. It hides the commandbar that is
unique to this sheet when the sheet is deactivated and erases the
commandbar name from the worksheet so that XL doesn't try to hide the
toolbar when the workbook is closed.

Private Sub Worksheet_deActivate()
Application.CommandBars("Abuse").Visible = False

With wksMacRec
   .Unprotect Password:=PWORD<----ERROR
   .Range("E2").Value = ""
   .Protect Password:=PWORD
End With
'ActiveWorkbook.Worksheets("Macro Records").Range("E2").Value = ""
End Sub

I'm getting an "object variable or with block variable not set" error.
The password in set as a public constant in another module in this same
workbook. So whatzzup?
Thanks as always.
Jim Thomlinson - 23 Jan 2006 23:30 GMT
Where is wksMacRec set. Is the sheet named that or is it set somewhere else???

set wksMacRec = sheets("Sheet1") '???

Signature

HTH...

Jim Thomlinson

> This code is on the worksheet module. It hides the commandbar that is
> unique to this sheet when the sheet is deactivated and erases the
[quoted text clipped - 16 lines]
> workbook. So whatzzup?
> Thanks as always.
JakeyC - 23 Jan 2006 23:31 GMT
I think it may be because PWORD needs to either be "PWORD" or before
using it, state PWORD = "mYPassWOrD"
Chip Pearson - 23 Jan 2006 23:32 GMT
As far as I can see in your code, you've never set the wksMacRec
variable. You need some code like

Dim  wksMacRec As Worksheet
Set wksMacRec = Worksheets("Sheet1")

Signature

Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

> This code is on the worksheet module. It hides the commandbar
> that is
[quoted text clipped - 22 lines]
> workbook. So whatzzup?
> Thanks as always.
GB - 24 Jan 2006 12:57 GMT
Testing methodoligy would suggest try commenting out the first affected line.
If the next line gives the same error, then it would suggest the cause that
others here have indicated.  If it is a different error (as obviously to
perform the requested function the protection must be turned off to do the
next step) then there is definetly a problem with the line indicated and it
is other than that suggested by others here.

> This code is on the worksheet module. It hides the commandbar that is
> unique to this sheet when the sheet is deactivated and erases the
[quoted text clipped - 16 lines]
> workbook. So whatzzup?
> Thanks as always.
davegb - 25 Jan 2006 15:25 GMT
Thanks for all your help. The problem was that wksMacRec was not set in
this macro. I forgot that a "set" has to be done in each separate macro
and can't be done publicly like setting a constant.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.