wdDoNotSaveChanges Not Working

G

Guest

I have a Table of Contents in a document that I am trying to add tab spaces
after the words Article and any number or roman numeral that may appear.
Because I don't want any other occurrence of Article being altered, I am
cutting and pasting the TOC into a new blank document, running a Find, adding
tab spaces, and then cutting and pasting back into the old document.
Everything works fine, except that I am still being prompted to Save the
document, even though I am using the wdDoNotSaveChanges command. Below is
the entire code. Any help would be greatly appreciated. Thanks.


Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:="TOC"
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Cut
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat (wdPasteDefault)
With Selection.Find
.Text = "article ^#^# "
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop
End With
Selection.Find.Execute
While Selection.Find.Found
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeText Text:=vbTab
Selection.Find.Execute
Wend
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:="TOC"
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1
With Selection.Find
.Text = "article ^# "
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop
End With
Selection.Find.Execute
While Selection.Find.Found
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeText Text:=vbTab
Selection.Find.Execute
Wend
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:="TOC"
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1
With Selection.Find
.Text = "article ^$^$^$^$^$^$ "
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop
End With
Selection.Find.Execute
While Selection.Find.Found
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeText Text:=vbTab
Selection.Find.Execute
Wend
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:="TOC"
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1
With Selection.Find
.Text = "article ^$^$^$^$^$ "
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop
End With
Selection.Find.Execute
While Selection.Find.Found
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeText Text:=vbTab
Selection.Find.Execute
Wend
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:="TOC"
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1
With Selection.Find
.Text = "article ^$^$^$^$ "
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop
End With
Selection.Find.Execute
While Selection.Find.Found
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeText Text:=vbTab
Selection.Find.Execute
Wend
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:="TOC"
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1
With Selection.Find
.Text = "article ^$^$^$ "
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop
End With
Selection.Find.Execute
While Selection.Find.Found
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeText Text:=vbTab
Selection.Find.Execute
Wend
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:="TOC"
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1
With Selection.Find
.Text = "article ^$^$ "
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop
End With
Selection.Find.Execute
While Selection.Find.Found
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeText Text:=vbTab
Selection.Find.Execute
Wend
Selection.HomeKey Unit:=wdStory
Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:="TOC"
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=1
With Selection.Find
.Text = "article ^$ "
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindStop
End With
Selection.Find.Execute
While Selection.Find.Found
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeText Text:=vbTab
Selection.Find.Execute
Wend
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Cut
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Selection.PasteAndFormat (wdPasteDefault)
End Sub
 
D

Doug Robbins

Use ActiveDocument.Saved=True

--
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
 
G

Guest

That worked perfectly! Thank you very much!

Doug Robbins said:
Use ActiveDocument.Saved=True

--
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
 

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