open & close file with vba

W

William Irish

This subroutine works fine the first time it is called. After that, the
following message pops up, "There is not enough memory or disk space to
complete the operation". I have to exit Word and restart to run the macro
again. If I don't save the file it works OK. If I take out the file save in
the routine but close the document manually I will still get the error
message.
I'm baffled!!!
Thanks for looking at this,
Bill

Sub PrintNewCheck()
'string fields have been set by previous sub

Const CHECK_DOC = "C:\Users\Overhead\QB\qb_blank.doc"
Dim iResponse As Integer
Dim oDoc As Document

Set oDoc = Application.Documents.Open(CHECK_DOC,
AddToRecentFiles:=False)
With ActiveDocument
.FormFields("Date").Result = sDateField
.FormFields("PayTo").Result = sPayToField
.FormFields("Money").Result = sMoneyField
.FormFields("DollarLine").Result = sDollarLineField
.FormFields("Memo").Result = sMemoField
iResponse = MsgBox("OK to print?", vbYesNo)
If iResponse = vbYes Then
.PrintOut
End If
End With
oDoc.Close wdDoNotSaveChanges
Set oDoc = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top