LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Trying to disable a custom commandbar button

Within a module I have created a custom toolbar, and added a button to it:

Sub CreateBar()
' This procedure creates a new temporary toolbar.
Dim ComBar As CommandBar, ComBarContrl As CommandBarControl
On Error GoTo ErrorHandler
' Create a new floating toolbar and make it visible.
On Error Resume Next
'Delete the toolbar if it already exists
CommandBars("NavBar").Delete
Set ComBar = CommandBars.Add(Name:="NavBar", Position:=msoBarFloating,
Temporary:=True)
ComBar.Visible = True
' Create a button with text & icon on the bar and set some properties.
Set ComBarContrl = ComBar.Controls.Add(Type:=msoControlButton,
Parameter:="GoBackBtn")
With ComBarContrl
.Caption = "Go &Back"
.Style = msoButtonIconAndCaption
.TooltipText = "Go back to the previously viewed worksheet"
'the onaction line tells the button to run a certain macro
.OnAction = "btnGoBack"
.Width = "85"
.FaceId = 41
End With
Exit Sub
ErrorHandler:
MsgBox "Error " & Err.Number & vbCr & Err.Description
Exit Sub
End Sub

In my Workbook_open event, I call the above 'CreateBar' sub.

In ThisWorkbook, in Workbook_SheetActivate, I call the 'enable_back' function:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)

'MsgBox ("The selected worksheet has changed!" & Sh.Name)
On Error Resume Next

If Sh.Name < "NavIndex" Then
ThisWorkbook.Worksheets("NavIndex").Range("A1").In sert Shift:=xlDown
ThisWorkbook.Worksheets("NavIndex").Range("A1") = Sh.Name
End If

If ThisWorkbook.Worksheets("NavIndex").UsedRange.Rows .Count 1 Then
enable_back
' ComBarContrl.Enabled

End Sub

Enable_back is in the same module as CreateBar, and looks like this:

Public Function enable_back()

CommandBars("NavBar").Controls("GoBackBtn").Enable d = True

End Function

I DON'T SEE ERRORS when enable_back is called.

In the same module is disable_back. Disable_back is identical to
enable_back, except that .Enabled = False.

I have a macro in the module that calls disable_back. Whenever disable_back
runs, I get the error "Run-time error '5': Invalid procedure call or
argument".

I haven't figured out how to fix this, but I'm very new to this and suspect
this must be something simple.

Thanks,
Steve



 
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
Option Button FaceID in a custom commandbar atpgroups Excel Programming 1 May 7th 08 09:29 PM
transparent button on custom commandbar ckoch Excel Programming 3 February 11th 06 07:41 PM
Creating a Custom commandbar button sifar Excel Programming 7 September 21st 05 07:22 PM
Creating a Custom commandbar button sifar Excel Programming 0 September 15th 05 11:27 PM
Disable CommandBar buttons while editing the cell Vinit[_2_] Excel Programming 1 August 16th 05 08:03 AM


All times are GMT +1. The time now is 08:02 AM.

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"