MS Office Forum / Word / Programming / December 2007
Moving code from MSWord to MSAccess
|
|
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
|
|
|