Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-29-2016, 02:44 AM
trent.bourne trent.bourne is offline Change Macro so it does not refer to "Active Document" Windows 10 Change Macro so it does not refer to "Active Document" Office 2013
Novice
Change Macro so it does not refer to "Active Document"
 
Join Date: Oct 2016
Posts: 1
trent.bourne is on a distinguished road
Exclamation Change Macro so it does not refer to "Active Document"

Hey Guys,

I need help changing this macro so that it runs in the background and does not chuck out an error as the document opens in the background.

I would prefer if I could add some code to bring the document to the front.

The code is

PHP Code:
Private Sub Document_Open()



'   Show mail merged folders.. not as <<id>>

    ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False





Save the file as an PDF File



    ActiveDocument
.Save

    ActiveDocument
.ExportAsFixedFormat OutputFileName:= _

        
"D:\Users\tmb842\Documents\VMPD\Compleated Documents (Mail Merge Finals)\VMPD - Practice First Contact - GP  Dentists.pdf" _

        
ExportFormat:=wdExportFormatPDFOpenAfterExport:=FalseOptimizeFor:= _

        wdExportOptimizeForPrint
Range:=wdExportAllDocumentFrom:=1To:=1_

        Item
:=wdExportDocumentContentIncludeDocProps:=TrueKeepIRM:=True_

        CreateBookmarks
:=wdExportCreateNoBookmarksDocStructureTags:=True_

        BitmapMissingFonts
:=TrueUseISO19005_1:=False

        



    ActiveDocument
.Close

    

 

End Sub 
Reply With Quote
  #2  
Old 10-29-2016, 03:24 AM
macropod's Avatar
macropod macropod is offline Change Macro so it does not refer to &quot;Active Document&quot; Windows 7 64bit Change Macro so it does not refer to &quot;Active Document&quot; Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

A Document_Open macro runs when you open a document. By definition, that document is both the active document and takes the foreground. When a macro executes a mailmerge, the output document becomes the active document. To see how you might go about implementing a mailmerge via a macro, see Send Mailmerge Output to Individual Files in the Mailmerge Tips and Tricks 'Sticky' thread at: https://www.msofficeforums.com/mail-...ps-tricks.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 10-30-2016, 01:49 AM
gmayor's Avatar
gmayor gmayor is offline Change Macro so it does not refer to &quot;Active Document&quot; Windows 10 Change Macro so it does not refer to &quot;Active Document&quot; Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If you assign variable names to the documents as you open them (in the same Word instance) and subsequently refer to the documents by those variable names, it will not matter whether they are in the foreground or background, visible or invisible.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
remove repeated words with " macro " or " wild cards " in texts with parentheses and commas jocke321 Word VBA 2 12-10-2014 11:27 AM
Change "File As" and "Display As" format davesp Outlook 0 10-14-2014 12:10 PM
How to Turn Off Message "Search from the beginning of a document" in a Macro sleake Word 10 10-15-2013 03:43 PM
How to add a "note" which is "active" when doing a powerpoint show Anders PowerPoint 0 01-22-2011 08:47 AM
How do I change the "and" to "or" with multiple Rules (and Alerts)? bschimmel Outlook 0 11-16-2009 05:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:36 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft