Word macro help- formatting and printing

J

JAnderson

Greetings,

I'm trying to create a simple formatting and printing macro, but am having
some trouble. I want the following to happen when the macro is run:

Select All
Font size to 8
Landscape format
Margins: Top .4, Bottom/left/right .5
Then print to a PDF using an add-in

Questions:
What if I want to give the macro to other users on different PCs? How do I
get it into their Normal.dot template?

How can I create a message box asking if the user wants to convert the
document into a PDF?

I used the macro recorder to get the following code, and it seems excessive:

Sub Macro1()

Selection.WholeStory
Selection.Font.Size = 8
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientLandscape
.TopMargin = InchesToPoints(0.4)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(11)
.PageHeight = InchesToPoints(8.5)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
ActivePrinter = "X Consulting PDF Publisher"
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True,
PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub
 
S

Shauna Kelly

Hi JAnderson
What if I want to give the macro to other users on different PCs? How do
I
get it into their Normal.dot template?

You don't! Leave users' normal.dot files alone. Instead, distribute your
macro in an add-in. For further information, see
Distributing macros to other users
http://www.word.mvps.org/FAQs/MacrosVBA/DistributeMacros.htm

How can I create a message box asking if the user wants to convert the
document into a PDF?

Something like this:

If MsgBox("Do you want to print to PDF?", vbYesNo) = vbYes Then
'put the code to print here
Else
'put here any code to run if the user says no
End If


Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

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

Similar Threads

Macro to fix header 0
Letterhead Macro 1
Page setup 14
Problem with Office 2003 vba in Office 2007 6
macro problems 0
Using Excel VBA to Format Word Document 0
Script 2
Run-time error '4608: Value out of range error 9

Top