HDI: retain envelope format settings?

C

C Hayes

I accidently posted this under forms. sorry.

How do I retain envelope format settings?

I'm having trouble retaining my envelope format settings. When I run the
macro it does not retain the formating from the ('set the envelope style)
section.

Sub printenvelope()
'instantiate the envelope
Dim mydoc As Document
Dim myenvelope As Envelope
Set mydoc = ActiveDocument
Set myenvelope = mydoc.Envelope

'set the envelope style
With myenvelope.AddressStyle
..Font.Name = "Arial"
..Font.Size = 12
..ParagraphFormat.Space1
..ParagraphFormat.LineUnitAfter = 0
..ParagraphFormat.LineUnitBefore = 0
End With

'print the envelope out
myenvelope.PrintOut extractaddress:=True, _
omitreturnaddress:=True, _
Size:="size 10", _
AddressFromLeft:=InchesToPoints(3), _
AddressFromTop:=InchesToPoints(1.5)

End Sub
 
R

Russ

You created an envelope object in memory and adjusted it's properties. When
your macros stop running the object may no longer be in memory, although you
didn't use 'set myenvelope = Nothing' to free memory, myenvelope with those
properties may no longer exist when you leave VBA run mode.

Have you tried recording a macro while **manually** changing Word's envelope
properties to see what kind of code it produces?
 
C

C Hayes

First, I think your idea of testing the manual build macro is great. I did
it to no success. Altering the font size in the dialog box is not captured
in the macro writer. I filled in an address on a blank document, created a
new macro, recorded the manual steps, changed the font in the dialog box by
right clicking the text and selecting font. When I went in to review the
created macro here's what I got:

Sub testenvelope()
'
' testenvelope Macro
' Macro recorded 10/30/2007 by jbradley
'
ActiveDocument.Envelope.PrintOut ExtractAddress:=False,
OmitReturnAddress _
:=True, PrintBarCode:=False, PrintFIMA:=False,
Height:=InchesToPoints( _
4.13), Width:=InchesToPoints(9.5), Address:="Johnny M Jones",
AutoText:= _
"ToolsCreateLabels1", ReturnAddress:="National Kidney Foundation", _
ReturnAutoText:="ToolsCreateLabels2",
AddressFromLeft:=wdAutoPosition, _
AddressFromTop:=wdAutoPosition,
ReturnAddressFromLeft:=wdAutoPosition, _
ReturnAddressFromTop:=wdAutoPosition, DefaultOrientation:= _
wdCenterLandscape, DefaultFaceUp:=True, PrintEPostage:=False
End Sub

Secondly, I am not following your logic in the envelope object being lost in
memory when I am both altering the attributes of the declaired object then
running a method (namely, 'printout') on said declaired object. My
housekeeping is a little sloppy, yes I did not release the object from memory.
 
R

Russ

It looks like you should change the "Envelope Return" and "Envelope Address"
styles in the Activedocument, if you want the settings that you change in
the current document to be retained.
ActiveDocument.Styles(wdStyleEnvelopeReturn).Font.Size = 16
ActiveDocument.Styles(wdStyleEnvelopeAddress).Font.Size = 16

The next new blank document will revert back to the default Normal.dot style
values. Since you shouldn't change other users Normal.dot, I would try to
change the style settings in another template other than Normal.dot and then
attach that altered template to documents when I wanted the envelope styles
changed.

Also look at VBA help for the UpdateStylesOnOpen property.
 
C

C Hayes

Russ,

I reallly like this answer. I haven't used it yet but it sounds like the
best way.

Thanks!

Chris
 

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