Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Obj Variable or withblock variable not set?

This is the code:

Private Sub CommandButton1_Click()
Const PWORD As String = "dave"
Dim wksSummary As Worksheet

wksSummary.Unprotect password:=PWORD <---- OBJ VAR NOT SET
Range("B:C").Select
Selection.ClearContents
Range("A1").Select


End Sub

This worked fine in a previous macro, but not today. Any ideas why
it's not recognizing wksSummary or password? Or is it something else?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Obj Variable or withblock variable not set?


You haven't told Excel what wksSummary refers to...
Set wksSummary = ActiveSheet
-or-
Set wksSummary = Worksheets("Summary").

However, if CommandButton1 is on Summary sheet and the
code is in that sheet's module then this will work...
("Me" is a reference to the sheet containing the module)
'--
Private Sub CommandButton1_Click()
Const PWORD As String = "dave"
Me.Unprotect password:=PWORD
Me.Range("B:C").ClearContents
Me.Range("A1").Select
End Sub
'--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"davegb"
wrote in message
This is the code:
Private Sub CommandButton1_Click()
Const PWORD As String = "dave"
Dim wksSummary As Worksheet

wksSummary.Unprotect password:=PWORD <---- OBJ VAR NOT SET
Range("B:C").Select
Selection.ClearContents
Range("A1").Select
End Sub

This worked fine in a previous macro, but not today. Any ideas why
it's not recognizing wksSummary or password? Or is it something else?
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Obj Variable or withblock variable not set?

On Feb 11, 1:51*pm, "Jim Cone" wrote:
You haven't told Excel what wksSummary refers to...
Set wksSummary = ActiveSheet
-or-
Set wksSummary = Worksheets("Summary").

However, if CommandButton1 is on Summary sheet and the
code is in that sheet's module then this will work...
("Me" is a reference to the sheet containing the module)
'--
Private Sub CommandButton1_Click()
Const PWORD As String = "dave"
Me.Unprotect password:=PWORD
Me.Range("B:C").ClearContents
Me.Range("A1").Select
End Sub
'--
Jim Cone
San Francisco, USAhttp://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

"davegb"
wrote in message
This is the code:
Private Sub CommandButton1_Click()
Const PWORD As String = "dave"
Dim wksSummary As Worksheet

wksSummary.Unprotect password:=PWORD <---- OBJ VAR NOT SET
Range("B:C").Select
Selection.ClearContents
Range("A1").Select
End Sub

This worked fine in a previous macro, but not today. Any ideas why
it's not recognizing wksSummary or password? Or is it something else?


Doh! Thanks, Jim.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object variable or withblock variable not set davegb Excel Programming 3 October 18th 05 02:57 PM
Sum cells based on a row variable and seperate column variable CheeseHeadTransplant Excel Worksheet Functions 10 September 23rd 05 06:59 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM


All times are GMT +1. The time now is 07:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"