wdDoNotSaveChanges doesn't work after saving in other format?

  • Thread starter Edward Mendelson
  • Start date
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
 
H

Helmut Weber

Hi Edward,
the workaround i am using is to save the file
in the format you like and save it again as,
lets say, "c:\temp\test.doc" as word-file. You
could prevent "c:\temp\test.doc" from appearing
in the recent files list, if you like.
Sub SaveAsW2()
With ActiveDocument
.SaveAs FileName:=.FullName, FileFormat:=102
.SaveAs FileName:="c:\test\test.doc", _
FileFormat:=wdFormatDocument, _
addtorecentfiles:=False
.Close
End With
End Sub
 
E

Edward Mendelson

Helmut Weber said:
Hi Edward,
the workaround i am using is to save the file
in the format you like and save it again as,
lets say, "c:\temp\test.doc" as word-file. You
could prevent "c:\temp\test.doc" from appearing
in the recent files list, if you like.
Sub SaveAsW2()
With ActiveDocument
.SaveAs FileName:=.FullName, FileFormat:=102
.SaveAs FileName:="c:\test\test.doc", _
FileFormat:=wdFormatDocument, _
addtorecentfiles:=False
.Close
End With
End Sub

Hi Helmut,

Thank you (again!). That will definitely work. In case of a very large file,
I was hoping there might be another workaround, but I can't find any.

Edward Mendelson
 
H

Helmut Weber

Hi Edward,
concerning WP-Fonts, if you are sure that there is only one
WP-Font in your doc and that this font is "WP TypographicSymbols",
then have a look at this:
Sub GetWPCharacter()
Dim oChr As Object ' object character
Dim iAsc As Integer ' integer asc
For Each oChr In ActiveDocument.Range.Characters
If Asc(oChr) = 40 Then ' applies to most decorative fonts
oChr.Select
iAsc = Dialogs(wdDialogInsertSymbol).charnum
If Asc(Selection.Text) <> iAsc Then
Select Case iAsc
Case 64: Selection.TypeText Text:=Chr$(147)
Case 65: Selection.TypeText Text:=Chr$(148)
Case 66: Selection.TypeText Text:=Chr$(45)
Case 67: Selection.TypeText Text:=Chr$(150)
End Select
End If
End If
Next
End Sub
So called decorative fonts reveal their names, sometimes,
by invoking Dialogs(wdDialogInsertSymbol), once a character,
usually asc(40), has been selected, and
Thisfont = Dialogs(wdDialogInsertSymbol).font.
But not here. The dialog returns "(normal text)" via VBA,
though Dialogs(wdDialogInsertSymbol).show displays
"WP TypographicSymbols".
(Too complicated even for the creators of it all?)
Only Dialogs(wdDialogInsertSymbol).charnum is of value.
Make an obsession of it or forget it.
I wonder, why it is just you and me all the time.
 
E

Edward Mendelson

Helmut Weber said:
Hi Edward,
concerning WP-Fonts, if you are sure that there is only one
WP-Font in your doc and that this font is "WP TypographicSymbols",
then have a look at this:
Sub GetWPCharacter()
Dim oChr As Object ' object character
Dim iAsc As Integer ' integer asc
For Each oChr In ActiveDocument.Range.Characters
If Asc(oChr) = 40 Then ' applies to most decorative fonts
oChr.Select
iAsc = Dialogs(wdDialogInsertSymbol).charnum
If Asc(Selection.Text) <> iAsc Then
Select Case iAsc
Case 64: Selection.TypeText Text:=Chr$(147)
Case 65: Selection.TypeText Text:=Chr$(148)
Case 66: Selection.TypeText Text:=Chr$(45)
Case 67: Selection.TypeText Text:=Chr$(150)
End Select
End If
End If
Next
End Sub
So called decorative fonts reveal their names, sometimes,
by invoking Dialogs(wdDialogInsertSymbol), once a character,
usually asc(40), has been selected, and
Thisfont = Dialogs(wdDialogInsertSymbol).font.
But not here. The dialog returns "(normal text)" via VBA,
though Dialogs(wdDialogInsertSymbol).show displays
"WP TypographicSymbols".
(Too complicated even for the creators of it all?)
Only Dialogs(wdDialogInsertSymbol).charnum is of value.
Make an obsession of it or forget it.
I wonder, why it is just you and me all the time.

Hi Helmut,

That's very elegant and it works!! Beautiful - and, as far as I know,
completely new.

The only trouble is that I cannot be certain that WP Typographic Symbols is
the only WP font in the document - it could be "WP MultinationalA Courier"
or any of twenty others! But unfortunately, as you say in your message,
Dialogs(wdDialogInsertSymbol).Font returns "(normal text)" - even though the
dialog itself shows WP Typographic Symbols!

I'm slightly obsessed this with this, partly because I have been wasting
hours of time fixing old WP documents imported into Word 2002, partly
because I want to create a tool to post on a WordPerfect site that I
maintain:

http://wpdos.org

There is a VERY out-of-date and inaccurate page on WP-Word conversions that
I want to update thoroughly.

By the way, I have managed to write a macro that seems to solve the problem,
but is very ugly. It works this way: save the current document in WinWord2.0
format; this exposes the invisible symbol fields; then search and replace
the symbol fields with native Windows characters. I will send it to you
separately later today or tomorrow.

Thank you again!

Edward Mendelson
 
E

Edward Mendelson

Helmut Weber said:
Hi Edward,
concerning WP-Fonts, if you are sure that there is only one
WP-Font in your doc and that this font is "WP TypographicSymbols",
then have a look at this:
Sub GetWPCharacter()
Dim oChr As Object ' object character
Dim iAsc As Integer ' integer asc
For Each oChr In ActiveDocument.Range.Characters
If Asc(oChr) = 40 Then ' applies to most decorative fonts
oChr.Select
iAsc = Dialogs(wdDialogInsertSymbol).charnum
If Asc(Selection.Text) <> iAsc Then
Select Case iAsc
Case 64: Selection.TypeText Text:=Chr$(147)
Case 65: Selection.TypeText Text:=Chr$(148)
Case 66: Selection.TypeText Text:=Chr$(45)
Case 67: Selection.TypeText Text:=Chr$(150)
End Select
End If
End If
Next
End Sub
So called decorative fonts reveal their names, sometimes,
by invoking Dialogs(wdDialogInsertSymbol), once a character,
usually asc(40), has been selected, and
Thisfont = Dialogs(wdDialogInsertSymbol).font.
But not here. The dialog returns "(normal text)" via VBA,
though Dialogs(wdDialogInsertSymbol).show displays
"WP TypographicSymbols".
(Too complicated even for the creators of it all?)
Only Dialogs(wdDialogInsertSymbol).charnum is of value.
Make an obsession of it or forget it.
I wonder, why it is just you and me all the time.

Hi Helmut,

Is this a possible workaround for the problem that
Dialogs(wdDialogInsertSymbol).font returns "(normal text)" -

As you said in your message: if I open the Insert Symbol dialog over the
invisible field, the font IS listed as "WP Typographic Symbols". With the
dialog open, I can tab to the Font: field and copy the name of the font to
the clipboard - and the correct font name is listed.

Is this possible in VBA? Can I copy the fontname and compare it to "WP
Typographic Symbols" and make this do what
Dialogs(wdDialogInsertSymbol).font does NOT do??

Thanks again...

Edward Mendelson
 
H

Helmut Weber

Hi Edward,
still another step towards a solution.
The macro copies the fontname from the dialog
into the clipboard and reads it from there.
Has to be combined with what we have so far,
which I leave up to you.
Please show us how the macro looks with the
combined sourcecode from both partial approaches.
Sub GetWPFont()
Dim rDcm As Range
Dim oChr As Object
Dim sFnt As String ' font name
Dim iFnt As Integer ' character number
Dim oDat As DataObject
Set oDat = New DataObject
Set rDcm = ActiveDocument.Range
For Each oChr In rDcm.Characters
If Asc(oChr) = 40 Then
' applies to most (or all) decorative fonts?
oChr.Select
' If Asc(Selection.Text) <> iAsc Then
' from previous psting would fit in here
' plus select case
SendKeys "%s^c" ' German version
Dialogs(wdDialogInsertSymbol).Display
iFnt = Dialogs(wdDialogInsertSymbol).charnum
oDat.GetFromClipboard
sFnt = oDat.GetText
Debug.Print sFnt, iFnt
End If
Next
End Sub
---
Note that you probably have to adapt the sendkeys
command to your language. The "%s" works with German
"Schriftart". Could be "f" for "Font" or "Fontname".
To access the clipboard you need a reference to
Microsoft Forms 2.0 Object library. Which I couldn't
find in the list of references, but appeared when
I inserted a form in my project. Remains the task,
to close the dialog programmatically, which could
be worth another thread.
Keep on.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 

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