Shipping Label Design

C

chaucersmom

I can't get labels to work on Word 2007. I've looked at the posts and help
items, but it seems much too complicated for what I want to do.

All I want to do is to print out one shipping label at a time with an
address from my Outlook contacts and a return address. Does someone have a
program that will help automate this? I just print it out on regular paper,
not on an Avery sheet.

Alternatively, I can easily design the label as I've done in WordPerfect,
but I want to be able to choose the address from my Outlook Contacts. Anyway
to do that?
 
D

Doug Robbins - Word MVP

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
 
C

chaucersmom

Thanks Doug for your response. Even though your solution was probably much
more complicated than I have ever tried, your directions were fantastic. I
have never even made a template before today!

Sadly, after I completed everything, I clicked on the "shipping label" on
the toolbar and an error message came up: "User-defined type not defined."
It highlighted "Dim oWord As Word.Application"

When I made the template, I simply pasted your lines into the label, rather
than using Ctr F9. I doubt, though, that this caused the error since it
didn't get as far as opening Word.

Any suggestions for fixing the "bug?"
 
D

Doug Robbins - Word MVP

You have missed this part of my instructions:

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.


--
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
 
D

Doug Robbins - Word MVP

Also, you cannot just copy and paste the

{ DOCVARIABLE varname}
{ DOCVARIABLE varcompany}
{ DOCVARIABLE varstreet}
{ DOCVARIABLE varcity} { DOCVARIABLE varstate} { DOCVARIABLE varzip}
{ DOCVARIABLE varcountry}

You could however copy and paste

DOCVARIABLE varname
DOCVARIABLE varcompany
DOCVARIABLE varstreet
DOCVARIABLE varcity DOCVARIABLE varstate DOCVARIABLE varzip
DOCVARIABLE varcountry

and then select each of the words DOCVARIABLE and the word after it in turn
and then press Ctrl+F9 to enclose it in Field Delimiters.


--
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
 
G

gr8auntieokie

Doug, I decided to see if _I_ could create your macro in Outlook, too. The
macro in Outlook is okay, but when I click on the contact name and then click
on the "MakeShippingLabel" button in my custom toolbar, a Word window opens
but nothing else happens. (If it matters, I did modify the macro so it would
search for the name of my Word template, changing the Word template from
"ShippingLabel.dot" to "MakeLabl.dot.")

Our firm stores all our documents, templates, etc. in Worldox (a document
management software) and I'm wondering if the path through Worldox to my
template might be what's stopping the Outlook macro from working. Any ideas??

Thanks.
Cyndie Browning
Software Support Specialist
GableGotwals
Tulsa, OK
 
D

Doug Robbins - Word MVP

Do you have the DOCVARIABLE fields in your template?

--
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
 
C

chaucersmom

Doug,

Thanks for your patience with my Shipping Label project and my ineptitude!

The "Make Shipping Label" button on the toolbar wouldn't run the program.
So I ran the Macro from the Macro menu and the error message I got was: "The
Macros in this project are disabled."

I went to the Trust Center, Macro Security in Outlook. The box checked
was the second one -- warnings for unsigned macros. Then I went to the Trust
Center in Word and checked the box Trust Access to VBA project model. Now
when I click on the Make Shipping Label button, a small box appears on the
Contacts screen with the First and Last name of the contact and that's all
that happens. MS Word doesn't open.

I am using Word 2007 and Outlook 2007. I saved my templates file as a .dotx
file. Any suggestions?
 
G

gr8auntieokie

Yes.


Doug Robbins - Word MVP said:
Do you have the DOCVARIABLE fields in your template?

--
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
 
D

Doug Robbins - Word MVP

If you press Alt+F9 in the Word window that opens, do you see the field
codes in the document?

--
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
 
D

Doug Robbins - Word MVP

The code should run without any changes to the Security Settings.

The box that you see containing the First and Last Name, should not really
appear but it does because when testing I had inserted a line of code

MsgBox cname

You can delete that if you do not want it.

If your template was saved as a .dotx, you will need to replace this line of
code

Set olabel = oWord.Documents.Add("ShippingLabel.dot")

with

Set olabel = oWord.Documents.Add("ShippingLabel.dotx")



--
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
 
G

gr8auntieokie

Yes, the codes are there.


Doug Robbins - Word MVP said:
If you press Alt+F9 in the Word window that opens, do you see the field
codes in the document?

--
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
 
C

chaucersmom

Yea, Doug, I'm almost there! This is a great program for me.

After changing the name of the file in the program to .dotx, my template
opened in Word, but the variables weren't filled in with the name and
address. (Just had the Docvariable lines that were in the template.)

Interestingly, when I saved the "label" which I made with your program, it
suggested as a name for the document, the name of the person for whom I was
making the label, even though that name wasn't visible in the document! The
same thing happened when I began with the "company", that is it suggested to
save it as the company name. But if I eliminated both the name and the
company from the template and then made a label, it suggested to save it as
the company name.

I think I'm a little confused as to how the program "knows" what the
separate parts of the address (city, state, zip, etc) since I enter the
address in the address box as I would if I were addressing an envelope as
follows:

5 Main Street
Cocoa, VA 24544

I am so close to debugging this that I hope you can help. Using Office and
Outlook 2007.
 
P

Peter T. Daniels

You don't want to put any actual data into a template (.dotx), because
then it will appear in every document, i.e., label, that you base on
that template!
 
C

chaucersmom

Thanks Peter for allowing me to clarify what I meant:

I only put the {Docvariable} in the template. The program was supposed to
replace the bracketed codes with the appropriate information from my Outlook
contacts into a shipping label.

The document that I saved was the result of running the program -- it was to
be a shipping label with the name and address replacing the Docvariables. It
was based on a template that I had created. I didn't save it over the
Template. The way I discovered the strange behavior, that is, the info
lurking in the background, was simply an accident.
 
D

Doug Robbins - Word MVP

It sounds like you need to toggle off the display of the field codes by
using Alt+F9.

When you enter contact details in Outlook, it divides up the individual
parts of the address into the following components:

FullName
CompanyName
BusinessAddressStreet
BusinessAddressCity
BusinessAddressState
BusinessAddressPostalCode
BusinessAddressCountry

Sometimes, if it is not clear how the parts should be divided, it will pop
up a dialog box asking you to confirm the choice that it has made.

--
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
 
D

Doug Robbins - Word MVP

The code is using Documents.Add to create a new document from the template.

--
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
You don't want to put any actual data into a template (.dotx), because
then it will appear in every document, i.e., label, that you base on
that template!
 
D

Doug Robbins - Word MVP

Have you tried updating the fields in the document? The code however should
do that.

I do not know anything about Worldox, but it could be interfering somewhere.

--
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
 
C

chaucersmom

You were absolutely right! I forgot to do the Alt f9 after I had entered the
variables. The program now works, but only IF I have a business address to
make a shipping label for. Most of my ship to addresses are HOME addresses.
How should I change the variables in the program to look for a HOME address.

I must say, I've learned a great deal from your posts to me! Thanks.
 
P

Peter T. Daniels

Note her second paragraph, where she says "the template opened" but
"the variables weren't filled in," as if she expected them to be. I
suppose she means that she opened a document based on the template
(such as by double-clicking on the template's name).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top