This may be too complicated for you, but if you do set it up, it will do all
of the work for you.
First, in Outlook, open the Visual Basic Editor and insert a module into the
Project1 item that will appear there and into that module, paste the
following code:
Sub MakeShippingLabel()
Dim objitem As Object
Dim cname As String
Dim ccompany As String
Dim cstreet As String
Dim ccity As String
Dim cstate As String
Dim czip As String
Dim ccountry As String
Dim oWord As Word.Application
Dim WordNotRunning As Boolean
Dim olabel As Document
Set objitem = GetCurrentItem()
MsgBox objitem.FullName
If objitem.Class = olContact Then
With objitem
cname = .FullName
ccompany = .CompanyName
cstreet = .BusinessAddressStreet
ccity = .BusinessAddressCity
cstate = .BusinessAddressState
czip = .BusinessAddressPostalCode
ccountry = .BusinessAddressCountry
End With
End If
Set objitem = Nothing
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word was not running
Set oWord = New Word.Application
WordNotRunning = True
End If
oWord.Visible = True
oWord.Activate
Set olabel = oWord.Documents.Add("ShippingLabel.dot")
With olabel
.Variables("varname").Value = cname
.Variables("varcompany").Value = ccompany
.Variables("varstreet").Value = cstreet
.Variables("varcity").Value = ccity
.Variables("varstate").Value = cstate
.Variables("varzip").Value = czip
.Variables("varcountry").Value = ccountry
.Range.Fields.Update
End With
If WordNotRunning Then
oWord.Quit
End If
Set oWord = Nothing
Set olabel = Nothing
End Sub
Function GetCurrentItem() As Object
On Error Resume Next
Select Case TypeName(Outlook.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = Outlook.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = Outlook.ActiveInspector.CurrentItem
Case Else
End Select
End Function
While in the Visual Basic Editor, select References from the Tools menu and
then place a check mark against the Microsoft Word ##.0 Object Library (##
will vary depending upon the version of Word that you are using.
Next, with the Contacts screen active in Outlook, right click on the Toolbar
at the top of the screen and select Customize, then on the Toolbars tab of
the Customize dialog, click on New then give the new Toolbar a name, say
Label Maker and click on OK. Then go to the Commands tab of the Customize
dialog and select the macros Category and you should see an item
"MakeShippingLabel" Click on it and Drag it onto the new toolbar. Then
drag that toolbar up to the top of the screen adjacent to the existing one.
Now in Word, create a new template that you save with the name of
ShippingLabel and in that template, setup the Return Address as you want it,
and using Ctrl+F9 for each pair of field delimiters, set up the following
fields in the configuration that you want the addressee's address to appear
{ DOCVARIABLE varname}
{ DOCVARIABLE varcompany}
{ DOCVARIABLE varstreet}
{ DOCVARIABLE varcity} { DOCVARIABLE varstate} { DOCVARIABLE varzip}
{ DOCVARIABLE varcountry}
Press Alt+F9 to toggle off the display of the field codes and then save and
close the template.
Now, when you select a contact in Outlook and click on the
Project1.MakeShippingLabel button, a document will be created from that
template in Word with the details of the selected contact appearing in it.
If you want, in the Contacts screeen in Outlook, if you right click on the
toolbar and select customize and then right click on the
Project1.MakeShippingLabel button, you can change the Name that appears on
the button from Project1.MakeShippingLabel to just Shipping Label.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com