Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Stumped by "Object variable not set" again

I have code that shows a specific commanbar when a particular worksheet
is activated, then hides the commandbar when the spreadsheet is
de-selected. I want to save the commandbar name so that when the
spreadsheet is closed, the last commandbar will be hidden. But I'm
getting the ever-present "Object or withblock variable not set" error.
Here is the sheet code:

Private Sub Worksheet_Activate()

Application.CommandBars("Abuse").Visible = True
cTBar.Name = "Abuse"<----ERROR
Call TBarNameSave

End Sub

cTBar is publicly declared as a Commandbar. So why won't it accept the
name?
Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Stumped by "Object variable not set" again

Declaring it as type Commandbar does not make it a commandbar, it just means
that it can be set to a commandbar via code, just declaring leaves it as
Nothing.

I don't think I fully understand what you are trying to do?

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"davegb" wrote in message
ups.com...
I have code that shows a specific commanbar when a particular worksheet
is activated, then hides the commandbar when the spreadsheet is
de-selected. I want to save the commandbar name so that when the
spreadsheet is closed, the last commandbar will be hidden. But I'm
getting the ever-present "Object or withblock variable not set" error.
Here is the sheet code:

Private Sub Worksheet_Activate()

Application.CommandBars("Abuse").Visible = True
cTBar.Name = "Abuse"<----ERROR
Call TBarNameSave

End Sub

cTBar is publicly declared as a Commandbar. So why won't it accept the
name?
Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Stumped by "Object variable not set" again

Objects need to be set, even if they are publicly declared. Give this a
whirl...

Private Sub Worksheet_Activate()

set cTBar = Application.CommandBars("Abuse")
cTBar.Visible = True
cTBar.Name = "Abuse"
Call TBarNameSave

End Sub

--
HTH...

Jim Thomlinson


"davegb" wrote:

I have code that shows a specific commanbar when a particular worksheet
is activated, then hides the commandbar when the spreadsheet is
de-selected. I want to save the commandbar name so that when the
spreadsheet is closed, the last commandbar will be hidden. But I'm
getting the ever-present "Object or withblock variable not set" error.
Here is the sheet code:

Private Sub Worksheet_Activate()

Application.CommandBars("Abuse").Visible = True
cTBar.Name = "Abuse"<----ERROR
Call TBarNameSave

End Sub

cTBar is publicly declared as a Commandbar. So why won't it accept the
name?
Thanks.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Stumped by "Object variable not set" again

Thanks for both of your replies.
Your solution worked, Jim. And I eliminated the cTBar.Name="Abuse" line
as no longer necessary.

Jim Thomlinson wrote:
Objects need to be set, even if they are publicly declared. Give this a
whirl...

Private Sub Worksheet_Activate()

set cTBar = Application.CommandBars("Abuse")
cTBar.Visible = True
cTBar.Name = "Abuse"
Call TBarNameSave

End Sub

--
HTH...

Jim Thomlinson


"davegb" wrote:

I have code that shows a specific commanbar when a particular worksheet
is activated, then hides the commandbar when the spreadsheet is
de-selected. I want to save the commandbar name so that when the
spreadsheet is closed, the last commandbar will be hidden. But I'm
getting the ever-present "Object or withblock variable not set" error.
Here is the sheet code:

Private Sub Worksheet_Activate()

Application.CommandBars("Abuse").Visible = True
cTBar.Name = "Abuse"<----ERROR
Call TBarNameSave

End Sub

cTBar is publicly declared as a Commandbar. So why won't it accept the
name?
Thanks.



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 With Block Variable Not Set" error help request Ken Loomis Excel Programming 8 June 27th 05 10:13 PM
Excel VBA - Storing text in a variable, and "'Cells' of object _Global failed" engineer[_2_] Excel Programming 3 April 23rd 04 11:35 PM
"Run-time error 91: Object variable or With block not set" Snedker Excel Programming 0 January 10th 04 09:37 AM
Ogilvy Help :) - "Object variable or With block variable not set" Mike Taylor Excel Programming 1 December 16th 03 07:21 AM
Exel2000 VBA - Creating a Command Bar - Error: "Object Variable or With not Set" keepitcool Excel Programming 0 August 11th 03 12:29 PM


All times are GMT +1. The time now is 11:49 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"