Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Object variable or With block variable not set?

Hi all,

I am a newbie "programmer-wannabe" and have this code:

Private Sub Worksheet_Activate()

Dim wSheet As Worksheet

If wSheet.ProtectContents = False Then
ProductCaution.Show
Protection.Show
Else

End If
End Sub

Don't know what this error means:

"Object variable or With block variable not set"

Can someone please help.

Thanks in advance and Happy Easter,
Emilio
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Object variable or With block variable not set?

Emilio,

Dim wSheet as Worksheet does nothing until you tell Excel what sheet it is...
Set wSheet = ActiveSheet.

Your code should be in the sheet module, therefore "ActiveSheet" or "Me" also
makes a reference to the sheet.

It appears to me that you have more problems then your object variable not
being set. The following code is my interpretation of what you want...

'-----------------------------------
Private Sub Worksheet_Activate()

If Me.ProtectContents = False Then
MsgBox "Sheet is unprotected. ", vbExclamation, " Emilio Says..."
Application.Dialogs(xlDialogProtectDocument).Show
End If

End Sub
'------------------------------------

Regards,
Jim Cone
San Francisco, USA



"Wind54Surfer" wrote in message
...
Hi all,

I am a newbie "programmer-wannabe" and have this code:

Private Sub Worksheet_Activate()

Dim wSheet As Worksheet

If wSheet.ProtectContents = False Then
ProductCaution.Show
Protection.Show
Else

End If
End Sub

Don't know what this error means:

"Object variable or With block variable not set"

Can someone please help.

Thanks in advance and Happy Easter,
Emilio

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Object variable or With block variable not set?

Thank you very much.

I would like to take a step forward and automatically protect that specific
sheet,

I tried:


"If Me.ProtectContents = False Then
Me.ProtectContents = True"

but doesn't work.

Thanks ,
Emilio

"Jim Cone" wrote:

Emilio,

Dim wSheet as Worksheet does nothing until you tell Excel what sheet it is...
Set wSheet = ActiveSheet.

Your code should be in the sheet module, therefore "ActiveSheet" or "Me" also
makes a reference to the sheet.

It appears to me that you have more problems then your object variable not
being set. The following code is my interpretation of what you want...

'-----------------------------------
Private Sub Worksheet_Activate()

If Me.ProtectContents = False Then
MsgBox "Sheet is unprotected. ", vbExclamation, " Emilio Says..."
Application.Dialogs(xlDialogProtectDocument).Show
End If

End Sub
'------------------------------------

Regards,
Jim Cone
San Francisco, USA



"Wind54Surfer" wrote in message
...
Hi all,

I am a newbie "programmer-wannabe" and have this code:

Private Sub Worksheet_Activate()

Dim wSheet As Worksheet

If wSheet.ProtectContents = False Then
ProductCaution.Show
Protection.Show
Else

End If
End Sub

Don't know what this error means:

"Object variable or With block variable not set"

Can someone please help.

Thanks in advance and Happy Easter,
Emilio


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Object variable or With block variable not set?


Emilio,

Me.Protect

More info in the VBA help file. Look up "Protect" or "Protect Method".

Jim Cone
San Francisco, USA



"Wind54Surfer" wrote in message
...
Thank you very much.
I would like to take a step forward and automatically protect that specific
sheet,
I tried:
"If Me.ProtectContents = False Then
Me.ProtectContents = True"
but doesn't work.
Thanks ,
Emilio




"Jim Cone" wrote:
Emilio,
Dim wSheet as Worksheet does nothing until you tell Excel what sheet it is...
Set wSheet = ActiveSheet.
Your code should be in the sheet module, therefore "ActiveSheet" or "Me" also
makes a reference to the sheet.
It appears to me that you have more problems then your object variable not
being set. The following code is my interpretation of what you want...
'-----------------------------------
Private Sub Worksheet_Activate()
If Me.ProtectContents = False Then
MsgBox "Sheet is unprotected. ", vbExclamation, " Emilio Says..."
Application.Dialogs(xlDialogProtectDocument).Show
End If

End Sub
'------------------------------------
Regards,
Jim Cone
San Francisco, USA


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Object variable or With block variable not set?

Sorry waqsn't thinking.

I got it. (Me!Protect)


Thanks for everything!

Emilio

"Wind54Surfer" wrote:

Thank you very much.

I would like to take a step forward and automatically protect that specific
sheet,

I tried:


"If Me.ProtectContents = False Then
Me.ProtectContents = True"

but doesn't work.

Thanks ,
Emilio

"Jim Cone" wrote:

Emilio,

Dim wSheet as Worksheet does nothing until you tell Excel what sheet it is...
Set wSheet = ActiveSheet.

Your code should be in the sheet module, therefore "ActiveSheet" or "Me" also
makes a reference to the sheet.

It appears to me that you have more problems then your object variable not
being set. The following code is my interpretation of what you want...

'-----------------------------------
Private Sub Worksheet_Activate()

If Me.ProtectContents = False Then
MsgBox "Sheet is unprotected. ", vbExclamation, " Emilio Says..."
Application.Dialogs(xlDialogProtectDocument).Show
End If

End Sub
'------------------------------------

Regards,
Jim Cone
San Francisco, USA



"Wind54Surfer" wrote in message
...
Hi all,

I am a newbie "programmer-wannabe" and have this code:

Private Sub Worksheet_Activate()

Dim wSheet As Worksheet

If wSheet.ProtectContents = False Then
ProductCaution.Show
Protection.Show
Else

End If
End Sub

Don't know what this error means:

"Object variable or With block variable not set"

Can someone please help.

Thanks in advance and Happy Easter,
Emilio


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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
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
Pivot Table - Object variable or with block variable not set? George Nicholson[_2_] Excel Programming 1 April 16th 04 09:12 PM
Error 91 - Object variable with block variable not set Jim[_35_] Excel Programming 2 November 27th 03 03:34 AM


All times are GMT +1. The time now is 05:45 AM.

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

About Us

"It's about Microsoft Excel"