I need a solution to execute a macro only once, when I open the document the
first time. When I open the same document again
(to make some changes) the macro should not be executed.
Maybe someone has a code-example?
thanks in advance,
Juergen N.
Sub AutoOpen()
Dim oVars As Variables
Dim vVar As Variant
Dim bExists As Boolean
Dim Opened As Integer
Set oVars = ActiveDocument.Variables
bExists = False
For Each vVar In oVars
If vVar.Name = "varOpened" Then
bExists = True
Exit For
End If
Next vVar
If bExists = False Then
oVars("varOpened").Value = 0
End If
Opened = oVars("varOpened").Value
If Opened = 0 Then
MsgBox "Document opened for the first time"
Else
MsgBox "Document previously opened"
End If
oVars("varOpened").Value = 1
ActiveDocument.Save
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
thanks for the example. I'll have a try.
best regards,
J�rgen N.
"Graham Mayor" <gma...@REMOVETHISmvps.org> schrieb im Newsbeitrag
news:ucLZBkhB...@TK2MSFTNGP04.phx.gbl...
--
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, originally posted via msnews.microsoft.com
"Juergen N." <j...@bauexpert.it> wrote in message
news:OWkqY9hB...@TK2MSFTNGP02.phx.gbl...