PDA

View Full Version : MS Word macro memory problem



tonupkid
04-04-2006, 07:56 AM
Edited by lucas, reason: cross-posted
Click here (http://www.excelguru.ca/XLKBA/XLKBA05.htm) for an explanation of cross-posting

I’ve a problem with a macro in Word. After running the macro several times I receive “the Run-time error 5112, there is not enough memory or disk space to complete the operation”. Restarting Outlook (using Word as editor) and Word solve this problem until the next error.

I went yesterday a little further with my search. It’s seems when I open just one document with the right bookmarks and select the macro, everything is working fine. I can repeat this for more than 20 times. But when I open 3 documents at once and want to save them with the macro the first two are working fine and the third is giving the memory error. So it’s definitely the Word macro what giving the error.

This is the code:
Sub SaveOrder()
Dim dlgSaveAs As FileDialog
Set dlgSaveAs = Application.FileDialog( _
FileDialogType:=msoFileDialogSaveAs)
dlgSaveAs.InitialFileName = ActiveDocument.Bookmarks("PoNumber").Range.Text & "-" & ActiveDocument.Bookmarks("CompanyName").Range.Text
dlgSaveAs.Show
If dlgSaveAs.InitialFileName <> "" Then dlgSaveAs.Execute
Set dlgSaveAs = Nothing
ActiveDocument.Close
End Sub

fumei
04-04-2006, 10:49 AM
1. Please read the thread re: cross-posting in Annoucements.

2. As I replied at Tek-Tips it is likely that you are making too many instances of Word.

3. No one here, looking at the code you supplied here, will be able to come up with much. There is nothing at all about the snippet that would indicate memory problems. That is because you do not supply everything that is going on. You mention Outlook - but there is no indication of Outlook in your code.

Again, there is nothing wrong with the code snippet above that indicates a memory issue. You need to supply all your code. You are making an assumption about the chunk that is giving you problems. Your assumption is very likely incorrect. For instances...unless you supply all the relevant code, how would someone not see that all your instances of OUTLOOK are taking up memory, and Word is doing fine...it is Outlook that is the issue.

I am not saying it is ( I agree that it is Word, and i have already posted at Tek-Tips what i think the problem is), but do you KNOW that?

Again, there is nothing at all in the code you posted here to show any memory problem.

4. Please use the VBA tags to put your code in a code window. It makes it easier to read.

Thanks.

lucas
04-04-2006, 11:51 AM
Original post edited to notify responders that this is a cross post.

tonupkid
04-04-2006, 11:56 AM
Gerry, just tried something else. Created 4 exactly the same documents (document 1, document 2 etc.). The documents are nearly empty. Just two bookmarks (CompanyName and PoNumber).
Put the macro in a fresh module (save) in normal. Created a new button on my toolbar. 2 documents saved with the maco, the third one is giving the statement error5112.

Option Explicit
Sub SaveOrder()
Dim dlgSaveAs As FileDialog
Set dlgSaveAs = Application.FileDialog( _
FileDialogType:=msoFileDialogSaveAs)
dlgSaveAs.InitialFileName = ActiveDocument.Bookmarks("PoNumber") _
.Range.Text & "-" & ActiveDocument.Bookmarks("CompanyName").Range.Text
dlgSaveAs.Show
If dlgSaveAs.InitialFileName <> "" Then dlgSaveAs.Execute
Set dlgSaveAs = Nothing
ActiveWindow.Close
End Sub


Brigitte

tonupkid
04-04-2006, 12:10 PM
Sorry for the cross post. I'm totally new with forums. Mostly I sort out my problems with the use of search engines. But this problem gives me a headache.

lucas
04-04-2006, 12:13 PM
Brigitte,
There must be more code that calls this sub. How are you opening the 4 documents?

lucas
04-04-2006, 12:15 PM
It's not a problem to cross post, just let people know that you are asking this in several places and provide a link so they can see what has been done to date.

fumei
04-04-2006, 01:04 PM
Further:dlgSaveAs.Show
If dlgSaveAs.InitialFileName <> "" Then dlgSaveAs.Executeis kind of a contradiction.

On one hand you display a dialog, with something already filled in. This gives the user a choice - OK, or Cancel. But you follow that with an explicit instruction that ignores the user. The instruction STATES if InitialFilename is not "" then Execute. This instruction, in of itself, does not give a fig about what the user thinks, or wishes. It is an either/or instruction. Why display a dialog if your LOGIC is already decided upon?

As, as I posted at Tek-Tips, and as Steve asked...what are you doing to get the 4 documents????

lucas
04-04-2006, 08:35 PM
Hi Brigitte,
We are confused because we don't have quite enough information to understand your problem. I would suggest that you post your full code and which module it is in(a regular module or ThisDocument) or even better if you can zip up your test files and post them here so we could take a look it would help us a lot.

If you post files be sure to remove any proprietary information from the document(including document properties)

to attach a file click on post reply then scroll down below the posting window to the "manage attachments" button.

tonupkid
04-04-2006, 10:55 PM
Gerry I zipped the bas/doc files. Also made a printscreen of the code.

The dialog is used for selecting a different directory. The bookmarks are just a useful help for the users for creating a filename. I going to test the if statement in the code. You mentioned it in your reply. I had also my doubts about this.

Brigitte

tonupkid
04-05-2006, 06:15 AM
I have solved my problem by creating a new macro. This one works.
Sub SaveOrder()
Dim oDlg As Dialog ' Object Dialog
Dim sPth As String ' String Path
sPth = "\\documents\everyone\orders\ (file://\\documents\everyone\orders\)"
Set oDlg = Dialogs(wdDialogFileSaveAs)
oDlg.Name = sPth & ActiveDocument.Bookmarks("PoNumber").Range.Text & "-" & ActiveDocument.Bookmarks("CompanyName").Range.Text
oDlg.Show
Set oDlg = Nothing
ActiveWindow.Close
End Sub


Thanks for the help.

Brigitte