Code Execution

F

Frank Tolstyka

I have a document that has VBA code attached to the Document_Open event.
Every once in a while this code will not execute. I have checked the macro
security when this happens and it is set at low. The code is included. The
document name is AIC1.doc.

Private Sub Document_Open()

Dim MyMerge As MailMerge
Dim DocName

DocName = ActiveDocument.Name
If UCase(Left(DocName, 3)) = "TMP" Then Exit Sub

Application.ActiveWindow.WindowState = wdWindowStateMinimize

Set MyMerge = ActiveDocument.MailMerge

If MyMerge.State = wdMainAndDataSource Then
MyMerge.Destination = wdSendToNewDocument
MyMerge.Execute
ActiveDocument.PrintOut Copies:=1, Background:=False
ActiveDocument.Close Savechanges:=wdDoNotSaveChanges
End If

Application.Quit Savechanges:=wdDoNotSaveChanges

End Sub

Thank you,

Frank
 
J

Jean-Guy Marcil

Frank Tolstyka was telling us:
Frank Tolstyka nous racontait que :
I have a document that has VBA code attached to the Document_Open
event. Every once in a while this code will not execute. I have

"Every once in a while " means...? (once per two years, once every month,
every other day? ...)
You mean nothing at all happens as if the code was ignored? Or the code
starts but does not terminate normally? Or it does, but produces wrong
results?

Depending on the frequency of the observed problem, you could try putting a
Stop command just under the two Dim statements.
Then, you will be able to debug and see if the code actually starts or not.
checked the macro security when this happens and it is set at low.
The code is included. The document name is AIC1.doc.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
F

Frank Tolstyka

Maybe once per 1/2 year. The code is not throwing an error, it produces the
correct results. The code does not execute at all. Placing a stop in the
code is not an option unfortunately since this document is to run
'automatically' via rexec from another system.
 
J

Jean-Guy Marcil

Frank Tolstyka was telling us:
Frank Tolstyka nous racontait que :
Maybe once per 1/2 year. The code is not throwing an error, it
produces the correct results. The code does not execute at all.
Placing a stop in the code is not an option unfortunately since this
document is to run 'automatically' via rexec from another system.

Twice a year?
This is going to be hard to find a pattern!

Sorry, but without more to go on, it is difficult to help, especially if the
code runs fine the rest of the time (How often would that be? I mean, about
twice a year it does not execute, but how often is it used in a year where
it runs successfully?)

Since the code is in a Document_Open sub, and that you say the whole thing
is automatic, maybe the problem is not in the code you posted, but in the
code that calls this document?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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