VBScript crashes MS Word with "Insufficient Memory"?

A

Alan

I have a MS Word document in which I have put links to various cells in an
Excel worksheet. I print the MS Word document from Excel through VBA
automation.

In MS Word I have checked "Update fields on Print", which updates the fields
when I issue wpApp.ActiveDocument.Printout

I am able to open the word document, and print it successfully. The problem
I am having is that I need to print it 3,000 times as I cycle through my
code.

After about the 20 records MS Word generates an error message:

Word has insufficient memory. You will not be able to undo this action once
it is completed. Do you want to continue? (Yes,No)

At this point I can only close winword, which leaves it running in the
background. So using task manager on the processes screen I kill winword.exe,
and then Excel crashes with:

Error #4248: This command is not available because no document is open.

Anyone have an idea for a workaround? Or a better way to manager data
transfer to Word (Bookmarks?)

Thanks in advance for your reply!!

Alan
 
A

Andi Mayer

After about the 20 records MS Word generates an error message:
try ActiveDocument.UndoClear

If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW
 
A

Alan

Andi, Thanks for your reply!

I was able to get past the problem by adding a document close and document
open command within my do loop, instead of before it. I have not tried your
solution; however, I will try it on the next go around.

For anyone else reading here is my old code:

Sub PrintWordDoc()
Dim wdApp As Object
Dim wdDoc As Object
Dim i As Integer

Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.documents.Open("C:\Templates\FormR1.dot")

Do Until Worksheets("DB").Cells(i, 1).Value = ""
wdApp.activedocument.Fields.Update
wdApp.activedocument.PrintOut Background:=True
i = i + 1
Loop
wdApp.activedocument.Close
wordfile = wdApp.Quit
Exit Sub


This is my revised code:

Sub PrintWordDoc()
Dim wdApp As Object
Dim wdDoc As Object
Dim i As Integer

Set wdApp = CreateObject("Word.Application")

Do Until Worksheets("DB").Cells(i, 1).Value = ""
Set wdDoc = wdApp.documents.Open("C:\Templates\FormR1.dot")
wdApp.activedocument.Fields.Update
wdApp.activedocument.PrintOut Background:=True
wdApp.activedocument.Close wdSaveChanges = False
i = i + 1
Loop
wordfile = wdApp.Quit
Exit Sub

Here are some other items that I found interferred with this process (FYI):
1. Norton Antivirus asked for a Virus Scan everytime a file was opened.
The only way to solve this was to totally uninstall Norton Antivirus.
2. There are several "automatic" options in MS Word which I turned off to
speed up the process:
Options, General, Automatic Update Links at Open
Options, General, Automatic Repagination
Options, Print, Printing Options, Background Print
Options, Print, Printing Options, Update Fields
Options, Save, Always create backup copy
Options, Spelling and Grammer, Check Spelling as you type
Options, Spelling and Grammer, Check Grammar as you type
Options, Security, just shut off everything, and Macro security low

I'm sure there is some automation way to disable these MS Word settings
"temporarily"; however, I'm not that Savvy. If you know how, please pass
that along--Along with any other suggestions you might have.

Thanks again!!

Alan
 

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