Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Nov 2001
    Location
    MI, USA
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    View/Print Macro (Word 2000)

    Since we get/send a lot of Word attachments, how about a macro or two to;
    A) force Word to open in the page view rather than normal, regardless of how it was orginally saved--I hate not seeing how a document looks as intended, let alone printing more pages than necessary, and;
    [img]/forums/images/smilies/cool.gif[/img] insert a preformatted header & footer to files, so that printouts include filename, author, Page X of Y etc. In this case, I think I would want this to be a function of print, so that even from Outlook, if I right-click the attachment and select print, all of my required info would be printed without changing or resaving the original file. FWIW, I tried macro-recording and unlike Excel, it's futile.

    Once I get this problem sorted out, I want to add this *feature* to everyone's computer within our organization. We already have a customized NORMAL.DOT for our default page setup and style, so should I attach the macro(s) to this template? THX in advance

    AJF

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: View/Print Macro (Word 2000)

    Hi AJ:

    Rather than customizing normal.dot, you would be better placed to create a special template that you put in the startup folder (to make it global). Among the reasons for this is that users would then be free to modify their normal.dot & also you won't lose all your customizations in normal.dot becomes infected by a macro virus.

    For the first problem, you can put this macro into a global template:

    Sub AutoOpen()
    <pre>If ActiveWindow.View.SplitSpecial = wdPaneNone Then
    ActiveWindow.ActivePane.View.Type = wdPageView
    Else
    ActiveWindow.View.Type = wdPageView
    End Sub</pre>


    For the second problem, I'm afraid someone else will have to jump in.

  3. #3
    Lounger
    Join Date
    Nov 2001
    Location
    MI, USA
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: View/Print Macro (Word 2000)

    Hi Phil,

    Maybe I'm missing something. Why would I need to create a new global template? I understand your rational for not using normal.dot, but I think as long as I have secured backups of normal.dot, then viruses are not a concern. Do you mean that with a global template, each and everytime that Word is opened, this macro would automatically run--regardless of which file is opened? This would make sense if Word doesn't open Normal.dot except for creating a new doc. If so, thanks for the insight here.

    In that case, from the visual basic editor, should I create a template called *Corporate Default Page View.dot* and put this macro into the M$ Word ObjectsThisDocument or into ModulesNewMacros?

    As for the second problem, what I currently have is in the below.

    THX

    AJF

    My Sample Code works ok when run on demand, although I'm sure it can be cleaner, i.e. getting rid of all those *Selection...*. I'd just like to have it run automatically from right-click to print file without manually opening the file--provided of course that the footer does not already have content, wouldn't want to overwrite previous info :<(.
    In that case, I would like to at least ensure that those wdfields are there and if not, have the macro put the missing stuff in (perhaps on the next line?).

    THX Again

    Sub Corporate_Page_Format()
    ' Corporate_Page_Format Macro
    ' Macro recorded 26 September 2001 by AJF
    '
    If ActiveWindow.View.Type <> wdPrintView Then
    ActiveWindow.View.Type = wdPrintView
    Else
    ActiveWindow.View.Type = wdPrintView
    End If

    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter

    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.Font.Size = 8
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
    "FILENAME ", PreserveFormatting:=True
    Selection.TypeText Text:=vbTab & "Page "
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
    "PAGE ", PreserveFormatting:=True
    Selection.TypeText Text:=" of "
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
    "NUMPAGES ", PreserveFormatting:=True
    Selection.TypeText Text:=vbTab
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
    "CREATEDATE @ ""d-MMM-yy""", PreserveFormatting:=True
    ' How would I get the Author's name on the next line below FILENAME?
    End Sub

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: View/Print Macro (Word 2000)

    Hi AJ:

    Let me start over. I was combining a couple of ideas without explaining.

    First, I left off a line on the macro; it should have a line that says

    End If

    just before End Sub.

    Secondly, the macro should go into the normal template so that you will open documents in page layout view.

    Third, corporate templates go a long way toward customizing styles & creating different types of reports, but still allowing users to customize their normal.dot. That way, they can create & use their own toolbars, shortcut keys, etc. It also means that every time the template is redesigned, users don't lose all their customizations. Having corporate macros, toolbars, & autotext in a global corporate template gives both the user & the management more flexibility. However, this is a totally separate issue from the one that you originally asked.

    The AutoOpen macro goes into the template (not each document). It will operate on any document to which the template is attached. If you had a "corporate" template, then documents to which the corporate template was attached would open in page layout view.

    As far as your second issue, I am not a VBA expert, so I can't help you. I hope that I've clarified what I was trying to say.

  5. #5
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: View/Print Macro (Word 2000)

    First, my preference is to not mess with normal.dot but rather use a combination of global and workgroup templates.

    I doubt that you want your header/footer printing on a sheet of labels. If you put it in normal.dot, you'll see it on your labels, and on your envelopes, and...

    Normal.dot is the place for users to store their own customizations like AutoText and macros. They will be very unhappy with you if they have gone to the trouble to create such and you blithely overwrite their work. When was the last time you were really happy that someone took it upon himself / herself to reorganize your desk top and top drawer?

    You can design custom templates that will be called from Outlook. You can have Autotext entries that contain the fields you are talking about. Word already has many of these built in.

    So, you have one kind of template for letters, a different one for faxes, a third kind for corporate reports, and a fourth for memos. They can all use common content stored in AutoText entries in a global template. They can all use shared custom toolbars and macros, or you can have different such for different kinds of documents.

    See <A target="_blank" HREF=http://addbalance.com/usersguide/templates.htm> Template Basics</A> (addbalance.com/usersguide/templates.htm) for information on the different kinds of templates, where they are stored, and how to get them to show up under the File => New dialog.

    You may want to ask in the Outlook group about how to set up a special template that will be used in printing / opening a Word attachment.
    Charles Kyle Kenyon
    Madison, Wisconsin

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: View/Print Macro (Word 2000)

    Hi Andy, this is a fun one!

    There is an application event you can hook to do special things at print time. This is the example code from online help:

    <pre>Private Sub App_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
    a = MsgBox("Have you checked the printer for letterhead?", vbYesNo)
    If a = vbNo Then Cancel = True
    End Sub</pre>

    You could ask the user whether she wants to update the headers/footers to the corporate standard. However, (1) this would occur on all docs, whether e-mail attachments or not, and (2) I actually don't know whether Word will fire this event when invoked to print from Outlook.

    A more reliable approach might be to change the Explorer setting to run a macro when printing from outside Word. In other words, under Tools, Folder Options, File Types, DOC, you would edit the DDE print setting as follows:

    From:

    [REM _DDE_Minimize][FileOpen("%1")][t=IsDocumentDirty()][FilePrint 0][SetDocumentDirty t][DocClose]

    To:

    [REM _DDE_Minimize][FileOpen("%1")][t=IsDocumentDirty()][Call MySub][FilePrint 0][SetDocumentDirty t][DocClose]

    This would affect all documents printed using the right-click-print method from My Computer/Windows Explorer as well. You could try to detect in the macro whether the doc is printing from Outlook by looking for the phrase "Temporary Internet Files" in the ActiveDocument.FullName property. Other indicia may present themselves upon further consideration.

    To distribute this change would be something of a challenge. On my system, the command string is stored in the registry under:

    HKEY_CLASSES_ROOTWord.Document.8shellPrintddeexec

    as the default value. Users cannot be trusted to run .reg files, however, and their nervousness about that probably is a good thing. VBScript is a less obtrusive method. VBA works, too. Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •