View Single Post
  #13   Report Post  
Posted to microsoft.public.word.docmanagement
chaucersmom chaucersmom is offline
external usenet poster
 
Posts: 15
Default Shipping Label Design

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.





"Doug Robbins - Word MVP" wrote:

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
"chaucersmom" wrote in message
...
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?


"Doug Robbins - Word MVP" wrote:

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
"chaucersmom" wrote in message
...
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?"

"Doug Robbins - Word MVP" wrote:

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
"chaucersmom" wrote in message
...
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?