Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My macro has screwed up my printing

Status
Not open for further replies.

lizdunn

IS-IT--Management
Jul 12, 2000
42
US
My problem is this: I need to create a letterhead template with certain sections protected. I have done this. However, I created a macro to choose specific paper trays when printing out the final letter and linked the macro to a toolbar button. But when I print from File-Print, ctrl+p, and the printer icon on my toolbar, they all choose the specific paper trays, instead of the default trays. What have i done wrong. Attached is the macro i created.

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 12/6/2005 by Win User

If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=""
End If
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1.65)
.RightMargin = InchesToPoints(1)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = 259
.OtherPagesTray = 260
.SectionStart = wdSectionContinuous
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
ActiveDocument.PrintOut Background:=False, Copies:=1
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
End If
End Sub Sub Macro1()

Thanks for any help.
 
Hi lizdunn,

The problem appears to be that you don't capture & restore the original print settings. To do that you need something like:
Code:
Sub PrintFile()
Dim P1, P2
With ActiveDocument
    If .ProtectionType <> wdNoProtection Then .Unprotect Password:=""
    With .Styles(wdStyleNormal).Font
        If .NameFarEast = .NameAscii Then .NameAscii = ""
        .NameFarEast = ""
    End With
    With .PageSetup
        P1 = .FirstPageTray
        P2 = .OtherPagesTray
        .FirstPageTray = 259
        .OtherPagesTray = 260
    End With
    .PrintOut Background:=False, Copies:=1
    With .PageSetup
        .FirstPageTray = P1
        .OtherPagesTray = P2
    End With
    If .ProtectionType = wdNoProtection Then .Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End With
End Sub


Cheers
 
Thank you, that did the trick! Now I have the problem of macro security. Every time I open the template i get that macro warning and on other workstations the macro doesn't work at all. Message says it doesn't exist or security blocked it! Any ideas? Thanks.
 
menu Tools -> Macro -> Security ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top