Marco to open a template in Word ready to e-mail

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can anyone help us with a Macro. We have 4 templates that we send as mails.
We want to have a dropdown tool bar in Outlook 2003 that will open each of
these templates in Word ready to send as a mail.

The files are in:
Z\templates\quote1.doc
Z\templates\quote2.doc
Etc
 
Hi Richi,

here is a sample for adding your own CommandBar with one -Button. To get
the button click event you need to declare a variable WithEvents.

You could add four buttons in this way or modify the sample for adding a
dropdown field and four buttons in it. For the DropDown the first
argument of Controls.Add is: msoControlButtonDropdown. It then returns
not a CommandBarButton but a CommandBarPopUp. This object in turn has a
Controls collection, which you can add the four buttons to. Please take
a look at the Object Browser for the objects and their hierarchy, it´s
the Office Library.

Private WithEvents YourButton as Office.CommandBarButton

Private Application_Startup()
Set YourButton=CreateCommandBarButton(Application.ActiveExplorer _
.CommandBars)
End Sub

Private Sub YourButton_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
' here your code goes
End Sub

Private Function CreateCommandBarButton(oBars As Office.CommandBars) As
Office.CommandBarButton
On Error Resume Next
Dim oMenu As Office.CommandBar
Dim oBtn As Office.CommandBarButton
Const BAR_NAME As String = "YourCommandBarName"
Const CMD_NAME As String = "YourButtonName"

Set oMenu = oBars(BAR_NAME)
If oMenu Is Nothing Then
Set oMenu = oBars.Add(BAR_NAME, msoBarTop, , True)
Set oBtn = oMenu.Controls.Add(msoControlButton, , CMD_NAME, , True)
oBtn.Caption = CMD_NAME
oBtn.Tag = CMD_NAME

Else
Set oBtn = oMenu.FindControl(, , CMD_NAME)
If oBtn Is Nothing Then
Set oBtn = oMenu.Controls.Add(msoControlButton, , CMD_NAME, ,
True)
End If
End If

oMenu.Visible = True
Set CreateCommandBarButton = oBtn
End Function


For opening a Word Document you need a reference on Word in your project
(Extras/References) and simply call e.g.:

Dim oWdApp as Word.Application
Dim oDoc as Word.Document
Set oWdApp=CreateObject("Word.Application")
oWdApp.Visible=True
Set oDoc=oWdApp.Documents.Open("YourFileName")
 
Thanks Nichael

That was just what we needed



Michael Bauer said:
Hi Richi,

here is a sample for adding your own CommandBar with one -Button. To get
the button click event you need to declare a variable WithEvents.

You could add four buttons in this way or modify the sample for adding a
dropdown field and four buttons in it. For the DropDown the first
argument of Controls.Add is: msoControlButtonDropdown. It then returns
not a CommandBarButton but a CommandBarPopUp. This object in turn has a
Controls collection, which you can add the four buttons to. Please take
a look at the Object Browser for the objects and their hierarchy, it´s
the Office Library.

Private WithEvents YourButton as Office.CommandBarButton

Private Application_Startup()
Set YourButton=CreateCommandBarButton(Application.ActiveExplorer _
.CommandBars)
End Sub

Private Sub YourButton_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
' here your code goes
End Sub

Private Function CreateCommandBarButton(oBars As Office.CommandBars) As
Office.CommandBarButton
On Error Resume Next
Dim oMenu As Office.CommandBar
Dim oBtn As Office.CommandBarButton
Const BAR_NAME As String = "YourCommandBarName"
Const CMD_NAME As String = "YourButtonName"

Set oMenu = oBars(BAR_NAME)
If oMenu Is Nothing Then
Set oMenu = oBars.Add(BAR_NAME, msoBarTop, , True)
Set oBtn = oMenu.Controls.Add(msoControlButton, , CMD_NAME, , True)
oBtn.Caption = CMD_NAME
oBtn.Tag = CMD_NAME

Else
Set oBtn = oMenu.FindControl(, , CMD_NAME)
If oBtn Is Nothing Then
Set oBtn = oMenu.Controls.Add(msoControlButton, , CMD_NAME, ,
True)
End If
End If

oMenu.Visible = True
Set CreateCommandBarButton = oBtn
End Function


For opening a Word Document you need a reference on Word in your project
(Extras/References) and simply call e.g.:

Dim oWdApp as Word.Application
Dim oDoc as Word.Document
Set oWdApp=CreateObject("Word.Application")
oWdApp.Visible=True
Set oDoc=oWdApp.Documents.Open("YourFileName")
 
Back
Top