H
Hans Troost
Hi All,
Using Word 2002, in a large and complex add-in (loaded with the
/L-commandline switch) I have a class module to intercept events and
modules with a lot of routines. One of the (public) routines is
FileSave() and in the class module I also intercept the
DocumentBeforeSave.
I have the following strange behaviour:
When Closing the document (also intercepted) and Word QUIT
(intercepted) and the document not saved: my specific FileSave is
nicely executed, after the DocumentBeforeSave event.
But (and this is the problem): when explicitly clicking the default
Save button (on the default Word-toolbar) or using the File-->Save
menu it does not execute FileSave.
What happens is the following;
The first time I press <Save> I see that the document is being saved
(simply see it happen on the screen and see the file time-stamp): The
LOG-file just shows:
11-08-03 14:40:01 DocumentBeforeSave start
11-08-03 14:40:01 WHT007000.TMP .saved: False
11-08-03 14:40:01 DocumentBeforeSave end
So the FileSave-routine is not executed while the file is saved (as
should be: doc.saved = False) !!! (I also update an Oracle database
with SetExpId in the FileSave and this did not happen)
The second atime the LOG-file shows:
11-08-03 14:40:04 DocumentBeforeSave start
11-08-03 14:40:04 WHT007000.TMP .saved: True
11-08-03 14:40:04 DocumentBeforeSave end
indicating that (indeeed the first time the document is really saved (
doc.saved = True)
Typing something in the document (.saved to become False now) en
pressing File-->Save shows on the screen the saving be done and in the
LOG-file:
11-08-03 14:40:10 DocumentBeforeSave start
11-08-03 14:40:10 WHT007000.TMP .saved: False (correct)
11-08-03 14:40:10 DocumentBeforeSave end
Since the first "real command" in FileSave is writing to the LOG-file
I should at least see a line with "<time-stamp> FileSave start" in the
LOG-file
This makes me ccompletely crazy: Why is the FileSave not executed???
I would be very pleased if someone can help me out.
Best regards,
Hans Troost
My DocumentBeforeSave is this:
Private Sub ActiveApp_DocumentBeforeSave(ByVal Doc As Document,
SaveAsUI As Boolean, Cancel As Boolean)
<write to LOG-file> "DocumentBeforeSave start"
<write to LOG-file> Doc.Name & " .saved: " & IIf(Doc.Saved,
"True", "False")
<write to LOG-file> "DocumentBeforeSave end"
End sub
and FileSave:
'
' FileSave Macro: intercepts the regular word SAVE command
' Saves the active document or template
'
Dim strDocFullName As String
Dim strDocName As String
Dim strExpID As String
'
' FileSave Macro: intercepts the regular word SAVE command
' Saves the active document or template
'
Dim strDocFullName As String
Dim strDocName As String
Dim strExpID As String
<write to LOG-file> "FileSave start"
<write to LOG-file> "File to be saved: " & ActiveDocument.FullName
<write to LOG-file> "Re-open: " & IIf(blnReOpen, "True", "False")
strDocFullName = ActiveDocument.FullName
strDocName = ActiveDocument.Name
If blnReOpen Then
With frmTMP2Doc
.lblInfo.Caption = "First time saving of experiment " &
Left(strDocName, 9) _
& vbNewLine & vbNewLine _
& "The document will be closed and re-opened"
.Show
End With
End If
ActiveDocument.Save
If IsHellasDoc(ActiveDocument) And Right(strDocName, 4) = ".TMP"
Then
ActiveDocument.Close
Call MyFileCopy(strDocFullName, gcolSettings(gcstrWorkDir) &
Left(strDocName, 9) & ".doc")
Call Kill(strDocFullName)
Call SetExpId ' increase the LastExp field in table
HELLAS_USERS in the database
If blnReOpen Then
Call DoOpenExp(Left(strDocName, 9) & ".doc",
gcolSettings(gcstrWorkDir))
End If
End If
If blnReOpen Then
Unload frmTMP2Doc
End If
<write to LOG-file> "FileSave end"
End Sub
Using Word 2002, in a large and complex add-in (loaded with the
/L-commandline switch) I have a class module to intercept events and
modules with a lot of routines. One of the (public) routines is
FileSave() and in the class module I also intercept the
DocumentBeforeSave.
I have the following strange behaviour:
When Closing the document (also intercepted) and Word QUIT
(intercepted) and the document not saved: my specific FileSave is
nicely executed, after the DocumentBeforeSave event.
But (and this is the problem): when explicitly clicking the default
Save button (on the default Word-toolbar) or using the File-->Save
menu it does not execute FileSave.
What happens is the following;
The first time I press <Save> I see that the document is being saved
(simply see it happen on the screen and see the file time-stamp): The
LOG-file just shows:
11-08-03 14:40:01 DocumentBeforeSave start
11-08-03 14:40:01 WHT007000.TMP .saved: False
11-08-03 14:40:01 DocumentBeforeSave end
So the FileSave-routine is not executed while the file is saved (as
should be: doc.saved = False) !!! (I also update an Oracle database
with SetExpId in the FileSave and this did not happen)
The second atime the LOG-file shows:
11-08-03 14:40:04 DocumentBeforeSave start
11-08-03 14:40:04 WHT007000.TMP .saved: True
11-08-03 14:40:04 DocumentBeforeSave end
indicating that (indeeed the first time the document is really saved (
doc.saved = True)
Typing something in the document (.saved to become False now) en
pressing File-->Save shows on the screen the saving be done and in the
LOG-file:
11-08-03 14:40:10 DocumentBeforeSave start
11-08-03 14:40:10 WHT007000.TMP .saved: False (correct)
11-08-03 14:40:10 DocumentBeforeSave end
Since the first "real command" in FileSave is writing to the LOG-file
I should at least see a line with "<time-stamp> FileSave start" in the
LOG-file
This makes me ccompletely crazy: Why is the FileSave not executed???
I would be very pleased if someone can help me out.
Best regards,
Hans Troost
My DocumentBeforeSave is this:
Private Sub ActiveApp_DocumentBeforeSave(ByVal Doc As Document,
SaveAsUI As Boolean, Cancel As Boolean)
<write to LOG-file> "DocumentBeforeSave start"
<write to LOG-file> Doc.Name & " .saved: " & IIf(Doc.Saved,
"True", "False")
<write to LOG-file> "DocumentBeforeSave end"
End sub
and FileSave:
'
' FileSave Macro: intercepts the regular word SAVE command
' Saves the active document or template
'
Dim strDocFullName As String
Dim strDocName As String
Dim strExpID As String
'
' FileSave Macro: intercepts the regular word SAVE command
' Saves the active document or template
'
Dim strDocFullName As String
Dim strDocName As String
Dim strExpID As String
<write to LOG-file> "FileSave start"
<write to LOG-file> "File to be saved: " & ActiveDocument.FullName
<write to LOG-file> "Re-open: " & IIf(blnReOpen, "True", "False")
strDocFullName = ActiveDocument.FullName
strDocName = ActiveDocument.Name
If blnReOpen Then
With frmTMP2Doc
.lblInfo.Caption = "First time saving of experiment " &
Left(strDocName, 9) _
& vbNewLine & vbNewLine _
& "The document will be closed and re-opened"
.Show
End With
End If
ActiveDocument.Save
If IsHellasDoc(ActiveDocument) And Right(strDocName, 4) = ".TMP"
Then
ActiveDocument.Close
Call MyFileCopy(strDocFullName, gcolSettings(gcstrWorkDir) &
Left(strDocName, 9) & ".doc")
Call Kill(strDocFullName)
Call SetExpId ' increase the LastExp field in table
HELLAS_USERS in the database
If blnReOpen Then
Call DoOpenExp(Left(strDocName, 9) & ".doc",
gcolSettings(gcstrWorkDir))
End If
End If
If blnReOpen Then
Unload frmTMP2Doc
End If
<write to LOG-file> "FileSave end"
End Sub