L
Lee
I have a custom toolbar which appears when a document is
created using a template. How do I close this custom
toolbar when the document closes as this toolbar is only
associated with that template/document.
Code for creating/showing toolbar:
Sub CreateToolbar()
Dim cbar As CommandBar, cbct1 As CommandBarControl
'Create a floating toolbar
Set cbar = CommandBars.Add(Name:="Agenda Hyperlink",
Position:=msoBarFloating)
cbar.Visible = True
'Add a custom button control to execute a macro
Set cbct1 = cbar.Controls.Add(Type:=msoControlButton)
cbct1.Visible = True
cbct1.Style = msoButtonCaption
cbct1.Caption = "Add Hyperlink"
'Run the following macro
cbct1.OnAction = "Hyperlink"
End Sub
Sub Hyperlink()
Dim fd As FileDialog, displaytext As String
'Create a FileDialog object as a File Picker dialog
box.
Set fd = Application.FileDialog
(msoFileDialogFilePicker)
'Use a With...End With block to reference the
FileDialog object.
With fd
'Set the initial path to the Agenda Attachments
folder.
.InitialFileName
= "\\alchemy\data\processes\documents\agenda attachments\"
.Title = "Select the File to which you want to
create the link"
'Use the Show method to display the File Picker
dialog box and return the user's action.
'If the user presses the action button...
If .Show = -1 Then
displaytext = .SelectedItems(1)
While InStr(displaytext, "\") > 0
displaytext = Mid(displaytext, InStr
(displaytext, "\") + 1)
Wend
displaytext = Left(displaytext, Len
(displaytext) - 4)
ActiveDocument.Hyperlinks.Add
Anchor:=Selection.Range, Address:=.SelectedItems(1),
TextToDisplay:=displaytext
' 'If the user presses Cancel...
Else
End If
End With
'Set the object variable to Nothing.
Set fd = Nothing
End Sub
I tried to create a custom toolbar by right-clicking on a
toolbar in Word (2002), Customize, Commands, Macros and
there should of been an option to create a custom toolbar
but there isn't!!!
Help anyone...
Lee
created using a template. How do I close this custom
toolbar when the document closes as this toolbar is only
associated with that template/document.
Code for creating/showing toolbar:
Sub CreateToolbar()
Dim cbar As CommandBar, cbct1 As CommandBarControl
'Create a floating toolbar
Set cbar = CommandBars.Add(Name:="Agenda Hyperlink",
Position:=msoBarFloating)
cbar.Visible = True
'Add a custom button control to execute a macro
Set cbct1 = cbar.Controls.Add(Type:=msoControlButton)
cbct1.Visible = True
cbct1.Style = msoButtonCaption
cbct1.Caption = "Add Hyperlink"
'Run the following macro
cbct1.OnAction = "Hyperlink"
End Sub
Sub Hyperlink()
Dim fd As FileDialog, displaytext As String
'Create a FileDialog object as a File Picker dialog
box.
Set fd = Application.FileDialog
(msoFileDialogFilePicker)
'Use a With...End With block to reference the
FileDialog object.
With fd
'Set the initial path to the Agenda Attachments
folder.
.InitialFileName
= "\\alchemy\data\processes\documents\agenda attachments\"
.Title = "Select the File to which you want to
create the link"
'Use the Show method to display the File Picker
dialog box and return the user's action.
'If the user presses the action button...
If .Show = -1 Then
displaytext = .SelectedItems(1)
While InStr(displaytext, "\") > 0
displaytext = Mid(displaytext, InStr
(displaytext, "\") + 1)
Wend
displaytext = Left(displaytext, Len
(displaytext) - 4)
ActiveDocument.Hyperlinks.Add
Anchor:=Selection.Range, Address:=.SelectedItems(1),
TextToDisplay:=displaytext
' 'If the user presses Cancel...
Else
End If
End With
'Set the object variable to Nothing.
Set fd = Nothing
End Sub
I tried to create a custom toolbar by right-clicking on a
toolbar in Word (2002), Customize, Commands, Macros and
there should of been an option to create a custom toolbar
but there isn't!!!
Help anyone...
Lee