E
Edward Mendelson
Hello,
This is a question about VBA in Word 2002. The problem involves the use of
wdDoNotSaveChanges when closing a file. This seems to be the subject of lots
of discussions online, because many people seem to have trouble making it
work, and none of the solutions I've found seem to help.
The problem seems to be this: If I save a file in WinWord 2.0 format, and
then try to close the file, Word will always prompt me to ask whether I want
to save the file. Nothing I've tried (see the commented lines below) seems
to prevent the prompt from appearing; the only workaround I've found is to
use SendKeys to say No when prompted, which of course is not exactly
elegant.
Here is a fragment of the macro, with various attempted solutions commented:
' all this is for saving the file in WinWord2 format
' based on code from Microsoft KB
Dim fcCnv As FileConverter
Dim strClass As String
Dim strFileName As String
strClass = "MSWordWin2"
strFileName = Environ("TEMP") & "\tempww2.doc"
' Loop through all installed converters.
For Each fcCnv In FileConverters
With fcCnv
' Test for conversion ClassName.
If .ClassName = strClass Then
' Save using the FileConverters.ClassName.
ActiveDocument.SaveAs FileName:=strFileName, _
FileFormat:=.SaveFormat, _
AddToRecentFiles:=False
End If
End With
Next fcCnv
' Having saved in Word2 format, close the file without saving
' The next line doesn't prevent the prompt,
' because Word already knows the file is saved - but in a different
format
ActiveDocument.Saved = True
' the SaveChanges= etc below doesn't help either
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
' SendKeys says No when asked to save changes
' No other workaround seems to work
SendKeys ("%" + "N")
Does anyone have a solution to this minor problem? Thanks in advance.
Edward Mendelson
This is a question about VBA in Word 2002. The problem involves the use of
wdDoNotSaveChanges when closing a file. This seems to be the subject of lots
of discussions online, because many people seem to have trouble making it
work, and none of the solutions I've found seem to help.
The problem seems to be this: If I save a file in WinWord 2.0 format, and
then try to close the file, Word will always prompt me to ask whether I want
to save the file. Nothing I've tried (see the commented lines below) seems
to prevent the prompt from appearing; the only workaround I've found is to
use SendKeys to say No when prompted, which of course is not exactly
elegant.
Here is a fragment of the macro, with various attempted solutions commented:
' all this is for saving the file in WinWord2 format
' based on code from Microsoft KB
Dim fcCnv As FileConverter
Dim strClass As String
Dim strFileName As String
strClass = "MSWordWin2"
strFileName = Environ("TEMP") & "\tempww2.doc"
' Loop through all installed converters.
For Each fcCnv In FileConverters
With fcCnv
' Test for conversion ClassName.
If .ClassName = strClass Then
' Save using the FileConverters.ClassName.
ActiveDocument.SaveAs FileName:=strFileName, _
FileFormat:=.SaveFormat, _
AddToRecentFiles:=False
End If
End With
Next fcCnv
' Having saved in Word2 format, close the file without saving
' The next line doesn't prevent the prompt,
' because Word already knows the file is saved - but in a different
format
ActiveDocument.Saved = True
' the SaveChanges= etc below doesn't help either
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
' SendKeys says No when asked to save changes
' No other workaround seems to work
SendKeys ("%" + "N")
Does anyone have a solution to this minor problem? Thanks in advance.
Edward Mendelson