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 / December 2007

Tip: Looking for answers? Try searching our database.

Moving code from MSWord to MSAccess

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kathy Webster - 30 Nov 2007 23:26 GMT
I have a macro in Word that I want to move to my MSAccess app and run from MSAccess. It merges a form file with a data file to a new screen, then prints and exits:

   Application.ScreenUpdating = False

   

       Documents.Open FileName:="K:\legalper\mergform.doc", ConfirmConversions:= _

           False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _

           PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _

           WritePasswordTemplate:="", Format:=wdOpenFormatAuto

       With ActiveDocument.MailMerge

          .Destination = wdSendToNewDocument

           .Execute

       End With

       ' PRINT AND EXIT

           Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _

           wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _

           ManualDuplexPrint:=False, Collate:=True, Background:=False, PrintToFile:= _

           False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _

           PrintZoomPaperHeight:=0

       ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

       Application.Quit SaveChanges:=wdDoNotSaveChanges    

Thanks to RM, I have successfully revised as follows, but it's jamming with my Application.PrintOut options in bold below:

Public Function Env()

   Dim wd As Object
   Dim wdActiveDoc As Object 'RM: Added this to help ensure that you're
                             'working on the document you intend to.
   Dim wdField As Object 'RM: Note the change in name here to avoid
                         'ambiguity with the Field object in both Word and
                         'Access.  As well, I changed the type, since
                         '(like Word.Application), you have to use late
                         'binding.
   
   Set wd = CreateObject("Word.Application")
   wd.Visible = True

   wd.Application.ScreenUpdating = False

   Set wdActiveDoc = wd.Documents.Open("K:\legalper\mergform.doc", False, False, _
                       False, "", "", False, "", "", 0)
   
   With wdActiveDoc.MailMerge
       .Destination = 0
       .Execute
   End With
   wd.Windows("mergform.doc").Activate
   wd.ActiveWindow.Close 0

   ' PRINT AND EXIT: PLEASE HELP ME HERE:

       wd.Application.PrintOut = "", 0, 0, 1, "", 0, False, True, False, _
       False, 0, 0, 0, 0
Doug Robbins - Word MVP - 01 Dec 2007 06:27 GMT
Replace

  With wdActiveDoc.MailMerge
       .Destination = 0
       .Execute
   End With
   wd.Windows("mergform.doc").Activate
   wd.ActiveWindow.Close 0


with

  With wdActiveDoc.MailMerge
       .Destination = 0
       .Execute
   End With

   wd.ActiveDocument.PrintOut Background: = False
   wd.Windows("mergform.doc").Activate
   wd.ActiveWindow.Close 0



Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

 I have a macro in Word that I want to move to my MSAccess app and run from MSAccess. It merges a form file with a data file to a new screen, then prints and exits:

     Application.ScreenUpdating = False

     

         Documents.Open FileName:="K:\legalper\mergform.doc", ConfirmConversions:= _

             False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _

             PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _

             WritePasswordTemplate:="", Format:=wdOpenFormatAuto

         With ActiveDocument.MailMerge

            .Destination = wdSendToNewDocument

             .Execute

         End With

         ' PRINT AND EXIT

             Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _

             wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _

             ManualDuplexPrint:=False, Collate:=True, Background:=False, PrintToFile:= _

             False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _

             PrintZoomPaperHeight:=0

         ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

         Application.Quit SaveChanges:=wdDoNotSaveChanges    

  Thanks to RM, I have successfully revised as follows, but it's jamming with my Application.PrintOut options in bold below:

 

 Public Function Env()

     Dim wd As Object
     Dim wdActiveDoc As Object 'RM: Added this to help ensure that you're
                               'working on the document you intend to.
     Dim wdField As Object 'RM: Note the change in name here to avoid
                           'ambiguity with the Field object in both Word and
                           'Access.  As well, I changed the type, since
                           '(like Word.Application), you have to use late
                           'binding.
     
     Set wd = CreateObject("Word.Application")
     wd.Visible = True

     wd.Application.ScreenUpdating = False
 
     Set wdActiveDoc = wd.Documents.Open("K:\legalper\mergform.doc", False, False, _
                         False, "", "", False, "", "", 0)
     
     With wdActiveDoc.MailMerge
         .Destination = 0
         .Execute
     End With
     wd.Windows("mergform.doc").Activate
     wd.ActiveWindow.Close 0

 

     ' PRINT AND EXIT: PLEASE HELP ME HERE:

 

         wd.Application.PrintOut = "", 0, 0, 1, "", 0, False, True, False, _
         False, 0, 0, 0, 0
Kathy Webster - 03 Dec 2007 17:45 GMT
Beautiful. Thank you.
 Replace

    With wdActiveDoc.MailMerge
         .Destination = 0
         .Execute
     End With
     wd.Windows("mergform.doc").Activate
     wd.ActiveWindow.Close 0
 

 with

    With wdActiveDoc.MailMerge
         .Destination = 0
         .Execute
     End With

     wd.ActiveDocument.PrintOut Background: = False
     wd.Windows("mergform.doc").Activate
     wd.ActiveWindow.Close 0

 

 --
 Hope this helps.

 Please reply to the newsgroup unless you wish to avail yourself of my
 services on a paid consulting basis.

 Doug Robbins - Word MVP

   "Kathy Webster" <slickdock@yahoo.com> wrote in message news:47509c33$0$16470$4c368faf@roadrunner.com...
   I have a macro in Word that I want to move to my MSAccess app and run from MSAccess. It merges a form file with a data file to a new screen, then prints and exits:

       Application.ScreenUpdating = False

       

           Documents.Open FileName:="K:\legalper\mergform.doc", ConfirmConversions:= _

               False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _

               PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _

               WritePasswordTemplate:="", Format:=wdOpenFormatAuto

           With ActiveDocument.MailMerge

              .Destination = wdSendToNewDocument

               .Execute

           End With

           ' PRINT AND EXIT

               Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _

               wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _

               ManualDuplexPrint:=False, Collate:=True, Background:=False, PrintToFile:= _

               False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _

               PrintZoomPaperHeight:=0

           ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

           Application.Quit SaveChanges:=wdDoNotSaveChanges    

    Thanks to RM, I have successfully revised as follows, but it's jamming with my Application.PrintOut options in bold below:

   

   Public Function Env()

       Dim wd As Object
       Dim wdActiveDoc As Object 'RM: Added this to help ensure that you're
                                 'working on the document you intend to.
       Dim wdField As Object 'RM: Note the change in name here to avoid
                             'ambiguity with the Field object in both Word and
                             'Access.  As well, I changed the type, since
                             '(like Word.Application), you have to use late
                             'binding.
       
       Set wd = CreateObject("Word.Application")
       wd.Visible = True

       wd.Application.ScreenUpdating = False
   
       Set wdActiveDoc = wd.Documents.Open("K:\legalper\mergform.doc", False, False, _
                           False, "", "", False, "", "", 0)
       
       With wdActiveDoc.MailMerge
           .Destination = 0
           .Execute
       End With
       wd.Windows("mergform.doc").Activate
       wd.ActiveWindow.Close 0

   

       ' PRINT AND EXIT: PLEASE HELP ME HERE:

   

           wd.Application.PrintOut = "", 0, 0, 1, "", 0, False, True, False, _
           False, 0, 0, 0, 0
 
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.