Absolution
New Member
- Joined
- Feb 7, 2005
- Messages
- 27
I have a set of *workbooks* which I access from a *workbook laid out like a menu* with form buttons assigned to macros. The *workbook* I am calling from has the following macro:
The *workbook* I am calling from this has the following code:
With this code to hide the menu if another *workbook* is activated:
For some reason, when I open the *workbook from Explorer* as a stand alone *workbook* it is fine and the menu appears as it is supposed to, but when I call it from the *menu Workbook* it does not open.
Anyone have any ideas ?
Code:
Sub OpenArtefact()
'
' OpenArtefact Macro
Workbooks.Open Filename:= _
"C:\SerimRal\Game 23 Information\Artefact Rumours.xls"
End Sub
The *workbook* I am calling from this has the following code:
Code:
Public Const TbarName = "SR23 Profile Options"
Sub Auto_Open()
On Error GoTo Errorhandler
Dim c
Dim i As Integer
Dim customBar As CommandBar
Dim CBar1
Dim newButton As CommandBarButton
'************************************************************************************
' Check the existing toolbars - if the one you want exists, make it visible
'************************************************************************************
For Each c In CommandBars
If c.Name = TbarName Then
c.Visible = True
Application.CommandBars(TbarName).Controls(1).Enabled = True
Application.CommandBars(TbarName).Controls(4).Enabled = True
For i = 2 To 3
Application.CommandBars(TbarName).Controls(i).Enabled = True
Next i
c.Delete
Exit Sub
End If
Next
'*************************************************************************************
' If haven't exited add the toolbar
' Position determines where it's displayed (e.g. msoBarTop, ...left or floating)
'*************************************************************************************
Set CBar1 = CommandBars.Add(Name:=TbarName, Position:=msoBarFloating, Temporary:=False)
With Application
'*********************************************************************************
' Add the number of controls that you want
'*********************************************************************************
For i = 1 To 7
CBar1.Controls.Add
Next i
'*********************************************************************************
' Assign the properties for each control
'
'*********************************************************************************
With CBar1
.Controls(1).Style = msoButtonCaption
.Controls(1).OnAction = "FindArtefact"
.Controls(1).Caption = "Locate Artefact "
.Controls(1).TooltipText = "Locate Artefact"
.Controls(1).Enabled = True
.Controls(2).Style = msoButtonCaption
.Controls(2).OnAction = "ManualArtInputter"
.Controls(2).Caption = "Manual Input "
.Controls(2).TooltipText = "Clear Fields to enable Location from manual Source"
.Controls(2).Enabled = True
.Controls(3).Style = msoButtonCaption
.Controls(3).OnAction = "AutoArtefactInput"
.Controls(3).Caption = "Auto Input "
.Controls(3).TooltipText = "Allows Location from listed rumours"
.Controls(3).Enabled = True
.Controls(4).Style = msoButtonCaption
.Controls(4).OnAction = "GotoFreeform"
.Controls(4).Caption = "Enter Freeform Results"
.Controls(4).TooltipText = "Allows Input of realm or know areas"
.Controls(4).Enabled = True
.Controls(5).Style = msoButtonCaption
.Controls(5).OnAction = "GotoCastle"
.Controls(5).Caption = "Go To Castle List "
.Controls(5).TooltipText = "Moves to castle listings"
.Controls(5).Enabled = True
.Controls(6).Style = msoButtonCaption
.Controls(6).OnAction = "GotoArtifacts"
.Controls(6).Caption = "Go to Artefact Rumours"
.Controls(6).TooltipText = "Moves to Artefact Rumour Sheet"
.Controls(6).Enabled = True
.Controls(7).Style = msoButtonCaption
.Controls(7).OnAction = "ExitProfile"
.Controls(7).Caption = "Exit Sheet "
.Controls(7).TooltipText = "Exits the Sheet"
.Controls(7).Enabled = True
'*********************************************************************************
' The "pop up" menu is a control with controls added to its commandbar
'*********************************************************************************
Application.CommandBars(TbarName).Controls.Add Type:=msoControlPopup, Before:=4
.Controls(4).TooltipText = "Update Option"
.Controls(4).Caption = "Updates "
With Application.CommandBars(TbarName).Controls(4).CommandBar
For i = 1 To 5
.Controls.Add
Next
.Controls(1).Style = msoButtonCaption
.Controls(1).OnAction = "UpdateGodNames"
.Controls(1).Caption = "Update God Names"
.Controls(1).TooltipText = "Updates Sheet to add new god names"
.Controls(2).Style = msoButtonCaption
.Controls(2).OnAction = "SortRumours"
.Controls(2).Caption = "Sort Rumours"
.Controls(2).TooltipText = "Sorts the Artefacts Rumours"
.Controls(3).Style = msoButtonCaption
.Controls(3).OnAction = "SortCastles"
.Controls(3).Caption = "Sort Castles"
.Controls(3).TooltipText = "Sorts the Castles into Alphabetical Order"
.Controls(4).Style = msoButtonCaption
.Controls(4).OnAction = "xmap"
.Controls(4).Caption = "X all Freeform"
.Controls(4).TooltipText = "This option resets the freeform map"
.Controls(5).Style = msoButtonCaption
.Controls(5).OnAction = "CalcSheet"
.Controls(5).Caption = "Calculate Sheet"
.Controls(5).TooltipText = "This option calculates the sheet"
End With
'*********************************************************************************
' Add "Dividers"
'*********************************************************************************
.Controls(2).BeginGroup = True
.Controls(4).BeginGroup = True
.Controls(5).BeginGroup = True
.Controls(8).BeginGroup = True
For i = 1 To 8
.Controls(i).Width = 100
Next
End With
'*************************************************************************************
' Display the commandbar - by default it should display on a single line
' (even if floating) - you should be able to play with height and width to
' change this - here the width is 100 (buttons are 90) so this forces height
' its actually the last parameter that changes the display (so although the
' following gives height as the width is just over the button size, if you
' define height as 50 it will override the width command and the toolbar will
' go back to a single line)
' You'll get an error with some of these values if the toolbar is not "floating"
'*************************************************************************************
CBar1.Width = 100
'CBar1.Height = 50
CBar1.Top = 500
CBar1.Left = 550
CBar1.Visible = True
Set CBar1 = Nothing
End With
Exit Sub
Errorhandler:
'*************************************************************************************
' Most likely error is setting width/ height of a non-floating toolbar.
'*************************************************************************************
Select Case Error
Case "Method 'Width' of object 'CommandBar' failed"
Message = "Toolbar is not floating - cannot vary width" & vbCrLf & vbCrLf & _
"Change toolbar position?"
response = MsgBox(Message, vbYesNo + vbQuestion, "Error")
Select Case response
Case vbYes
CBar1.Position = msoBarFloating
Resume Next
Case vbNo
Resume Next
End Select
Case "Method 'Height' of object 'CommandBar' failed"
Message = "Toolbar is not floating - cannot vary height" & vbCrLf & vbCrLf & _
"Change toolbar position?"
response = MsgBox(Message, vbYesNo + vbQuestion, "Error")
Select Case response
Case vbYes
CBar1.Position = msoBarFloating
Resume Next
Case vbNo
Resume Next
End Select
Case Else
MsgBox "Unexpected error: " & Error
End Select
End Sub
Sub Auto_Close()
For Each c In CommandBars
If c.Name = TbarName Then
c.Delete
End If
Next
End Sub
With this code to hide the menu if another *workbook* is activated:
Code:
Private Sub Workbook_Activate()
'************************************************************************************
' This event makes the custom menu visible when workbook is active
'************************************************************************************
On Error Resume Next
With Application.CommandBars(TbarName)
.Visible = True
End With
End Sub
Private Sub Workbook_Deactivate()
'************************************************************************************
' This event hides the custom menu when another sheet is active
'************************************************************************************
On Error Resume Next
With Application.CommandBars(TbarName)
.Visible = False
End With
End Sub
For some reason, when I open the *workbook from Explorer* as a stand alone *workbook* it is fine and the menu appears as it is supposed to, but when I call it from the *menu Workbook* it does not open.
Anyone have any ideas ?