Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

Undo changes to graphics macro??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lady of the Flowers - 29 Jun 2007 14:40 GMT
Background info:  my office is changing to a preprinted letterhead.  I want
to create a document template that shows the graphics on the template but
does not print them.  This template will be used by everyone in the office.

I received some help earlier created a macro to accomplish the above task.  
I created a macro that sets the letterhead logo brightness to max and
contrast to min when the print button is pressed or file print is executed.  
But immediately after printing, I would like the graphics to reappear.  Is it
possible to create a macro that does this automatically?  I'm new to VBA and
I'm not familiar with codes, so any additional help in this area would be
appreciated.  Thanks!
Jay Freedman - 29 Jun 2007 14:53 GMT
It would be helpful to see the code you already have. In general, though,
the idea is to follow the Print dialog's .Show command or the .PrintOut
command with enough repetitions of the ActiveDocument.Undo command to bring
the document back to the condition it had at the start of the macro.

In the case of the PrintOut command, it will be necessary to include the
optional Background parameter

  ActiveDocument.PrintOut Background:=False

to make the macro pause until printing is completed before the next
statement executes.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> Background info:  my office is changing to a preprinted letterhead.
> I want to create a document template that shows the graphics on the
[quoted text clipped - 9 lines]
> automatically?  I'm new to VBA and I'm not familiar with codes, so
> any additional help in this area would be appreciated.  Thanks!
Lady of the Flowers - 29 Jun 2007 15:16 GMT
The Macro I included in the template is as follows...

Sub FilePrint()
'' Macro1 Macro
' Macro recorded 6/29/2007 by Christina Livingston
'
   If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
       ActiveWindow.Panes(2).Close
   End If
   If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
       ActivePane.View.Type = wdOutlineView Then
       ActiveWindow.ActivePane.View.Type = wdPrintView
   End If
   ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
   Selection.HeaderFooter.Shapes("Picture 1").Select
   Selection.ShapeRange.Fill.Visible = msoFalse
   Selection.ShapeRange.Fill.Solid
   Selection.ShapeRange.Fill.Transparency = 0#
   Selection.ShapeRange.Line.Weight = 0.75
   Selection.ShapeRange.Line.DashStyle = msoLineSolid
   Selection.ShapeRange.Line.Style = msoLineSingle
   Selection.ShapeRange.Line.Transparency = 0#
   Selection.ShapeRange.Line.Visible = msoFalse
   Selection.ShapeRange.LockAspectRatio = msoTrue
   Selection.ShapeRange.Rotation = 0#
   Selection.ShapeRange.PictureFormat.Brightness = 1#
   Selection.ShapeRange.PictureFormat.Contrast = 0#
   Selection.ShapeRange.PictureFormat.CropLeft = 0#
   Selection.ShapeRange.PictureFormat.CropRight = 0#
   Selection.ShapeRange.PictureFormat.CropTop = 0#
   Selection.ShapeRange.PictureFormat.CropBottom = 0#
   Selection.ShapeRange.Left = 0#
   Selection.ShapeRange.Top = 0#
   Selection.ShapeRange.RelativeHorizontalPosition = _
       wdRelativeHorizontalPositionPage
   Selection.ShapeRange.RelativeVerticalPosition = _
       wdRelativeVerticalPositionPage
   Selection.ShapeRange.Left = InchesToPoints(0)
   Selection.ShapeRange.Top = InchesToPoints(0)
   Selection.ShapeRange.LockAnchor = False
   Selection.ShapeRange.LayoutInCell = True
   Selection.ShapeRange.WrapFormat.AllowOverlap = True
   Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
   Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
   Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
   Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
   Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
   Selection.ShapeRange.WrapFormat.Type = 3
   Selection.ShapeRange.ZOrder 5
   Selection.HeaderFooter.Shapes("Picture 2").Select
   Selection.HeaderFooter.Shapes("Picture 2").Select
   Selection.ShapeRange.Fill.Visible = msoFalse
   Selection.ShapeRange.Fill.Solid
   Selection.ShapeRange.Fill.Transparency = 0#
   Selection.ShapeRange.Line.Weight = 0.75
   Selection.ShapeRange.Line.DashStyle = msoLineSolid
   Selection.ShapeRange.Line.Style = msoLineSingle
   Selection.ShapeRange.Line.Transparency = 0#
   Selection.ShapeRange.Line.Visible = msoFalse
   Selection.ShapeRange.LockAspectRatio = msoTrue
   Selection.ShapeRange.Rotation = 0#
   Selection.ShapeRange.PictureFormat.Brightness = 1#
   Selection.ShapeRange.PictureFormat.Contrast = 0#
   Selection.ShapeRange.PictureFormat.CropLeft = 0#
   Selection.ShapeRange.PictureFormat.CropRight = 0#
   Selection.ShapeRange.PictureFormat.CropTop = 0#
   Selection.ShapeRange.PictureFormat.CropBottom = 0#
   Selection.ShapeRange.Left = 0#
   Selection.ShapeRange.Top = 738#
   Selection.ShapeRange.RelativeHorizontalPosition = _
       wdRelativeHorizontalPositionPage
   Selection.ShapeRange.RelativeVerticalPosition = _
       wdRelativeVerticalPositionPage
   Selection.ShapeRange.Left = InchesToPoints(0)
   Selection.ShapeRange.Top = InchesToPoints(10.25)
   Selection.ShapeRange.LockAnchor = False
   Selection.ShapeRange.LayoutInCell = True
   Selection.ShapeRange.WrapFormat.AllowOverlap = True
   Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
   Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
   Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
   Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
   Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
   Selection.ShapeRange.WrapFormat.Type = 3
   Selection.ShapeRange.ZOrder 5
   Selection.HeaderFooter.Shapes("Picture 3").Select
   Selection.ShapeRange.Fill.Visible = msoFalse
   Selection.ShapeRange.Fill.Solid
   Selection.ShapeRange.Fill.Transparency = 0#
   Selection.ShapeRange.Line.Weight = 0.75
   Selection.ShapeRange.Line.DashStyle = msoLineSolid
   Selection.ShapeRange.Line.Style = msoLineSingle
   Selection.ShapeRange.Line.Transparency = 0#
   Selection.ShapeRange.Line.Visible = msoFalse
   Selection.ShapeRange.LockAspectRatio = msoTrue
   Selection.ShapeRange.Rotation = 0#
   Selection.ShapeRange.PictureFormat.Brightness = 1#
   Selection.ShapeRange.PictureFormat.Contrast = 0#
   Selection.ShapeRange.PictureFormat.CropLeft = 0#
   Selection.ShapeRange.PictureFormat.CropRight = 0#
   Selection.ShapeRange.PictureFormat.CropTop = 0#
   Selection.ShapeRange.PictureFormat.CropBottom = 0#
   Selection.ShapeRange.Left = 0#
   Selection.ShapeRange.Top = 741.6
   Selection.ShapeRange.RelativeHorizontalPosition = _
       wdRelativeHorizontalPositionPage
   Selection.ShapeRange.RelativeVerticalPosition = _
       wdRelativeVerticalPositionPage
   Selection.ShapeRange.Left = InchesToPoints(0)
   Selection.ShapeRange.Top = InchesToPoints(10.3)
   Selection.ShapeRange.LockAnchor = False
   Selection.ShapeRange.LayoutInCell = True
   Selection.ShapeRange.WrapFormat.AllowOverlap = True
   Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
   Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
   Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
   Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
   Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
   Selection.ShapeRange.WrapFormat.Type = 3
   Selection.ShapeRange.ZOrder 5
' FilePrint Macro
' Prints the active document
'
   Dialogs(wdDialogFilePrint).Show

End Sub
Sub FilePrintDefault()
'' Macro1 Macro
' Macro recorded 6/29/2007 by Christina Livingston
'
   If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
       ActiveWindow.Panes(2).Close
   End If
   If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
       ActivePane.View.Type = wdOutlineView Then
       ActiveWindow.ActivePane.View.Type = wdPrintView
   End If
   ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
   Selection.HeaderFooter.Shapes("Picture 1").Select
   Selection.ShapeRange.Fill.Visible = msoFalse
   Selection.ShapeRange.Fill.Solid
   Selection.ShapeRange.Fill.Transparency = 0#
   Selection.ShapeRange.Line.Weight = 0.75
   Selection.ShapeRange.Line.DashStyle = msoLineSolid
   Selection.ShapeRange.Line.Style = msoLineSingle
   Selection.ShapeRange.Line.Transparency = 0#
   Selection.ShapeRange.Line.Visible = msoFalse
   Selection.ShapeRange.LockAspectRatio = msoTrue
   Selection.ShapeRange.Rotation = 0#
   Selection.ShapeRange.PictureFormat.Brightness = 1#
   Selection.ShapeRange.PictureFormat.Contrast = 0#
   Selection.ShapeRange.PictureFormat.CropLeft = 0#
   Selection.ShapeRange.PictureFormat.CropRight = 0#
   Selection.ShapeRange.PictureFormat.CropTop = 0#
   Selection.ShapeRange.PictureFormat.CropBottom = 0#
   Selection.ShapeRange.Left = 0#
   Selection.ShapeRange.Top = 0#
   Selection.ShapeRange.RelativeHorizontalPosition = _
       wdRelativeHorizontalPositionPage
   Selection.ShapeRange.RelativeVerticalPosition = _
       wdRelativeVerticalPositionPage
   Selection.ShapeRange.Left = InchesToPoints(0)
   Selection.ShapeRange.Top = InchesToPoints(0)
   Selection.ShapeRange.LockAnchor = False
   Selection.ShapeRange.LayoutInCell = True
   Selection.ShapeRange.WrapFormat.AllowOverlap = True
   Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
   Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
   Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
   Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
   Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
   Selection.ShapeRange.WrapFormat.Type = 3
   Selection.ShapeRange.ZOrder 5
   Selection.HeaderFooter.Shapes("Picture 2").Select
   Selection.HeaderFooter.Shapes("Picture 2").Select
   Selection.ShapeRange.Fill.Visible = msoFalse
   Selection.ShapeRange.Fill.Solid
   Selection.ShapeRange.Fill.Transparency = 0#
   Selection.ShapeRange.Line.Weight = 0.75
   Selection.ShapeRange.Line.DashStyle = msoLineSolid
   Selection.ShapeRange.Line.Style = msoLineSingle
   Selection.ShapeRange.Line.Transparency = 0#
   Selection.ShapeRange.Line.Visible = msoFalse
   Selection.ShapeRange.LockAspectRatio = msoTrue
   Selection.ShapeRange.Rotation = 0#
   Selection.ShapeRange.PictureFormat.Brightness = 1#
   Selection.ShapeRange.PictureFormat.Contrast = 0#
   Selection.ShapeRange.PictureFormat.CropLeft = 0#
   Selection.ShapeRange.PictureFormat.CropRight = 0#
   Selection.ShapeRange.PictureFormat.CropTop = 0#
   Selection.ShapeRange.PictureFormat.CropBottom = 0#
   Selection.ShapeRange.Left = 0#
   Selection.ShapeRange.Top = 738#
   Selection.ShapeRange.RelativeHorizontalPosition = _
       wdRelativeHorizontalPositionPage
   Selection.ShapeRange.RelativeVerticalPosition = _
       wdRelativeVerticalPositionPage
   Selection.ShapeRange.Left = InchesToPoints(0)
   Selection.ShapeRange.Top = InchesToPoints(10.25)
   Selection.ShapeRange.LockAnchor = False
   Selection.ShapeRange.LayoutInCell = True
   Selection.ShapeRange.WrapFormat.AllowOverlap = True
   Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
   Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
   Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
   Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
   Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
   Selection.ShapeRange.WrapFormat.Type = 3
   Selection.ShapeRange.ZOrder 5
   Selection.HeaderFooter.Shapes("Picture 3").Select
   Selection.ShapeRange.Fill.Visible = msoFalse
   Selection.ShapeRange.Fill.Solid
   Selection.ShapeRange.Fill.Transparency = 0#
   Selection.ShapeRange.Line.Weight = 0.75
   Selection.ShapeRange.Line.DashStyle = msoLineSolid
   Selection.ShapeRange.Line.Style = msoLineSingle
   Selection.ShapeRange.Line.Transparency = 0#
   Selection.ShapeRange.Line.Visible = msoFalse
   Selection.ShapeRange.LockAspectRatio = msoTrue
   Selection.ShapeRange.Rotation = 0#
   Selection.ShapeRange.PictureFormat.Brightness = 1#
   Selection.ShapeRange.PictureFormat.Contrast = 0#
   Selection.ShapeRange.PictureFormat.CropLeft = 0#
   Selection.ShapeRange.PictureFormat.CropRight = 0#
   Selection.ShapeRange.PictureFormat.CropTop = 0#
   Selection.ShapeRange.PictureFormat.CropBottom = 0#
   Selection.ShapeRange.Left = 0#
   Selection.ShapeRange.Top = 741.6
   Selection.ShapeRange.RelativeHorizontalPosition = _
       wdRelativeHorizontalPositionPage
   Selection.ShapeRange.RelativeVerticalPosition = _
       wdRelativeVerticalPositionPage
   Selection.ShapeRange.Left = InchesToPoints(0)
   Selection.ShapeRange.Top = InchesToPoints(10.3)
   Selection.ShapeRange.LockAnchor = False
   Selection.ShapeRange.LayoutInCell = True
   Selection.ShapeRange.WrapFormat.AllowOverlap = True
   Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
   Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
   Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
   Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
   Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
   Selection.ShapeRange.WrapFormat.Type = 3
   Selection.ShapeRange.ZOrder 5
' FilePrintDefault Macro
' Prints the active document using the current defaults
'
   ActiveDocument.PrintOut

End Sub

Any suggestions on where I should add the information you provided
previously?  Basically, I need you to spell it out for my if you would be so
kind. : )

> It would be helpful to see the code you already have. In general, though,
> the idea is to follow the Print dialog's .Show command or the .PrintOut
[quoted text clipped - 22 lines]
> > automatically?  I'm new to VBA and I'm not familiar with codes, so
> > any additional help in this area would be appreciated.  Thanks!
Lady of the Flowers - 29 Jun 2007 18:52 GMT
Scratch that last question.  I ended up figuring out that I was just not
using enough repetitions for the ActiveDocument.Undo code.  I realized this
when I went to manually click the undo button to restore the graphic in my
document, and I saw just how many operations were conducted (63 total).  So I
entered ActiveDocument.Undo 63 and it worked.  Now, can you explain why I
would need the ActiveDocument.PrintOut Background:=False for the PrintOut
Command?  I don't have it in the macro right now, and everything seems to be
working fine.

> The Macro I included in the template is as follows...
>
[quoted text clipped - 277 lines]
> > > automatically?  I'm new to VBA and I'm not familiar with codes, so
> > > any additional help in this area would be appreciated.  Thanks!
Jay Freedman - 30 Jun 2007 01:49 GMT
The macros you showed don't contain the ActiveDocument.Undo statement,
which should be just before the End Sub statement of each macro. If
you omit the Background parameter, the behavior of the
ActiveDocument.PrintOut method is to immediately continue on to the
next statement while the printer gets started. Since the .PrintOut is
currently the last thing the macro does, that's not a problem. Once
you put the .Undo after it, though, Word starts undoing the changes
while the document is still being sent to the printer. It's possible
that what the printer gets is a partially "undone" document. Setting
Background to False tells Word to do all the printing first, and then
start the .Undo.

By the way, most of the statements the recorder put into your macros
aren't necessary -- they just repeat all the settings in the Format
Picture dialog that you didn't change. Look at
http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm to see
how you can make the macros "lean and mean".

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>Scratch that last question.  I ended up figuring out that I was just not
>using enough repetitions for the ActiveDocument.Undo code.  I realized this
[quoted text clipped - 286 lines]
>> > > automatically?  I'm new to VBA and I'm not familiar with codes, so
>> > > any additional help in this area would be appreciated.  Thanks!

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.