Home |
Search |
Today's Posts |
#1
|
|||
|
|||
wdDoNotSaveChanges Not Working
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 |
#2
|
|||
|
|||
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 "Kurtis" wrote in message ... 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 |
#3
|
|||
|
|||
That worked perfectly! Thank you very much!
"Doug Robbins" wrote: 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 "Kurtis" wrote in message ... 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 |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Word 2003 - File and Tools drowndown menus stopped working | Microsoft Word Help | |||
Word 97 templates not working properly in Word 2003 | Microsoft Word Help | |||
zip code issues when working with mail merge and excel | Mailmerge | |||
Autocomplete for autotext not working? | Microsoft Word Help | |||
Converting hyperlinks in .doc to working links in .htm... | Microsoft Word Help |