Can macros carry out UNDO an option?

G

Greg Maxey

Sub ScratchMacro()
With ActiveDocument
MsgBox .Paragraphs.Last.Range.Text
.Range.InsertAfter "Yes macros can do undo actions"
MsgBox .Paragraphs.Last.Range.Text
ActiveDocument.Undo
MsgBox .Paragraphs.Last.Range.Text
End With
End Sub
 
D

Designingsally

i tired the technique you mentioned to the macros displayed below. I m
getting some error can you pls help me out

Sub ScratchMacro()
Dim oRng As Range
Dim rslt As VbMsgBoxResult
Set myRange = ActiveDocument.Range
With myRange.FInd
..Text = "<([A-Z]{2,})>"
..MatchWildcards = True
..Wrap = wdFindStop
..Forward = True
While .Execute
myRange.Select
If myRange.Text <> "TABLE" Then
If myRange.Text <> "OF" Then
If myRange.Text <> "RIO" Then
If myRange.Text <> "OST" Then
If myRange.Text <> "RLO" Then
If myRange.Text <> "NEXT" Then
If myRange.Text <> "CONTENTS" Then
If myRange.Text <> "AUDIO" Then
If myRange.Text <> "TEXT" Then
If myRange.Text <> "NOTE" Then
If myRange.Text <> "TIP" Then
If myRange.Text <> "MCQ" Then
If myRange.Text <> "WILL" Then
If myRange.Text <> "TRADE" Then
If myRange.Text <> "OR" Then
Set oRng = myRange.Duplicate
oRng.Move wdCharacter, -5
oRng.MoveEnd wdCharacter, 4
If Not oRng.Text = "the " Then
If Not oRng.Text = "The " Then
rslt = Msgbox(prompt:="Add 'the' before this acronym?", _
Buttons:=vbYesNoCancel & " The word " & oRng & " on page " &
Selection.Information(wdActiveEndPageNumber) & " is selected")
If rslt = vbCancel Then Exit Sub
If rslt = vbYes Then
Selection.InsertBefore "the "
myRange.Collapse wdCollapseEnd
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

End If
End If
End If
End If
myRange.Collapse wdCollapseEnd
Wend
End With
Set myRange = Nothing
End Sub
--
I believe in Hope.

DesigningSally


Greg Maxey said:
Sub ScratchMacro()
With ActiveDocument
MsgBox .Paragraphs.Last.Range.Text
.Range.InsertAfter "Yes macros can do undo actions"
MsgBox .Paragraphs.Last.Range.Text
ActiveDocument.Undo
MsgBox .Paragraphs.Last.Range.Text
End With
End Sub
 
D

Doug Robbins - Word MVP

Sometimes it is going to be a lot easier to help us if in addition to the
code that you are trying to use, you also tell us in plain English what you
are starting with and what you are trying to achieve.

If your code errors out. you should also indicate which line of code is
causing the error.

--
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, originally posted via msnews.microsoft.com
Designingsally said:
i tired the technique you mentioned to the macros displayed below. I m
getting some error can you pls help me out

Sub ScratchMacro()
Dim oRng As Range
Dim rslt As VbMsgBoxResult
Set myRange = ActiveDocument.Range
With myRange.FInd
.Text = "<([A-Z]{2,})>"
.MatchWildcards = True
.Wrap = wdFindStop
.Forward = True
While .Execute
myRange.Select
If myRange.Text <> "TABLE" Then
If myRange.Text <> "OF" Then
If myRange.Text <> "RIO" Then
If myRange.Text <> "OST" Then
If myRange.Text <> "RLO" Then
If myRange.Text <> "NEXT" Then
If myRange.Text <> "CONTENTS" Then
If myRange.Text <> "AUDIO" Then
If myRange.Text <> "TEXT" Then
If myRange.Text <> "NOTE" Then
If myRange.Text <> "TIP" Then
If myRange.Text <> "MCQ" Then
If myRange.Text <> "WILL" Then
If myRange.Text <> "TRADE" Then
If myRange.Text <> "OR" Then
Set oRng = myRange.Duplicate
oRng.Move wdCharacter, -5
oRng.MoveEnd wdCharacter, 4
If Not oRng.Text = "the " Then
If Not oRng.Text = "The " Then
rslt = Msgbox(prompt:="Add 'the' before this acronym?", _
Buttons:=vbYesNoCancel & " The word " & oRng & " on page " &
Selection.Information(wdActiveEndPageNumber) & " is selected")
If rslt = vbCancel Then Exit Sub
If rslt = vbYes Then
Selection.InsertBefore "the "
myRange.Collapse wdCollapseEnd
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

End If
End If
End If
End If
myRange.Collapse wdCollapseEnd
Wend
End With
Set myRange = Nothing
End Sub
 
G

Greg Maxey

I have to agree with what Doug has suggested. Still I took a stab at what I
thought you were after:

Sub ScratchMacro()
Dim oRng As Range
Dim oRngDup As Range
Dim rslt As VbMsgBoxResult
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "<([A-Z]{2,})"
.MatchWildcards = True
.Wrap = wdFindStop
.Forward = True
While .Execute
oRng.Select
Select Case oRng.Text
'Exclude first case words.
Case Is = "TABLE", "OF", "RIO", "OST", "RLO", "NEXT", "CONTENTS",
"AUDIO", "TEXT", _
"NOTE", "TIP", "MCQ", "WILL", "TRADE", "OR"
oRng.Collapse wdCollapseEnd
'Process all other words
Case Else
Set oRngDup = oRng.Duplicate
With oRngDup
.Move wdCharacter, -5
.MoveEnd wdCharacter, 4
If Not .Text = "the " Or Not .Text = "The " Then
Select Case MsgBox("Add " & Chr(34) & "the" & Chr(34) & " before
" & oRng & " on page " & Selection.Information(wdActiveEndPageNumber) & "?",
vbQuestion + vbYesNoCancel, "Add artical?")
Case vbCancel
Exit Sub
Case vbYes
oRng.InsertBefore "the "
oRng.Collapse wdCollapseEnd
End Select
End If
End With
End Select
Wend
End With
Set oRng = Nothing
Selection.HomeKey wdStory
End Sub



i tired the technique you mentioned to the macros displayed below. I m
getting some error can you pls help me out

Sub ScratchMacro()
Dim oRng As Range
Dim rslt As VbMsgBoxResult
Set myRange = ActiveDocument.Range
With myRange.FInd
.Text = "<([A-Z]{2,})>"
.MatchWildcards = True
.Wrap = wdFindStop
.Forward = True
While .Execute
myRange.Select
If myRange.Text <> "TABLE" Then
If myRange.Text <> "OF" Then
If myRange.Text <> "RIO" Then
If myRange.Text <> "OST" Then
If myRange.Text <> "RLO" Then
If myRange.Text <> "NEXT" Then
If myRange.Text <> "CONTENTS" Then
If myRange.Text <> "AUDIO" Then
If myRange.Text <> "TEXT" Then
If myRange.Text <> "NOTE" Then
If myRange.Text <> "TIP" Then
If myRange.Text <> "MCQ" Then
If myRange.Text <> "WILL" Then
If myRange.Text <> "TRADE" Then
If myRange.Text <> "OR" Then
Set oRng = myRange.Duplicate
oRng.Move wdCharacter, -5
oRng.MoveEnd wdCharacter, 4
If Not oRng.Text = "the " Then
If Not oRng.Text = "The " Then
rslt = Msgbox(prompt:="Add 'the' before this acronym?", _
Buttons:=vbYesNoCancel & " The word " & oRng & " on page "
& Selection.Information(wdActiveEndPageNumber) & " is selected")
If rslt = vbCancel Then Exit Sub
If rslt = vbYes Then
Selection.InsertBefore "the "
myRange.Collapse wdCollapseEnd
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

End If
End If
End If
End If
myRange.Collapse wdCollapseEnd
Wend
End With
Set myRange = Nothing
End Sub
Sub ScratchMacro()
With ActiveDocument
MsgBox .Paragraphs.Last.Range.Text
.Range.InsertAfter "Yes macros can do undo actions"
MsgBox .Paragraphs.Last.Range.Text
ActiveDocument.Undo
MsgBox .Paragraphs.Last.Range.Text
End With
End Sub
 
G

Greg Maxey

The If statement should read:

If Not .Text = "the " And Not .Text = "The " Then

vice

If Not .Text = "the " Or Not .Text = "The " Then

Greg said:
I have to agree with what Doug has suggested. Still I took a stab at
what I thought you were after:

Sub ScratchMacro()
Dim oRng As Range
Dim oRngDup As Range
Dim rslt As VbMsgBoxResult
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "<([A-Z]{2,})"
.MatchWildcards = True
.Wrap = wdFindStop
.Forward = True
While .Execute
oRng.Select
Select Case oRng.Text
'Exclude first case words.
Case Is = "TABLE", "OF", "RIO", "OST", "RLO", "NEXT", "CONTENTS",
"AUDIO", "TEXT", _
"NOTE", "TIP", "MCQ", "WILL", "TRADE", "OR"
oRng.Collapse wdCollapseEnd
'Process all other words
Case Else
Set oRngDup = oRng.Duplicate
With oRngDup
.Move wdCharacter, -5
.MoveEnd wdCharacter, 4
If Not .Text = "the " Or Not .Text = "The " Then
Select Case MsgBox("Add " & Chr(34) & "the" & Chr(34) & "
before " & oRng & " on page " &
Selection.Information(wdActiveEndPageNumber) & "?", vbQuestion +
vbYesNoCancel, "Add artical?") Case vbCancel
Exit Sub
Case vbYes
oRng.InsertBefore "the "
oRng.Collapse wdCollapseEnd
End Select
End If
End With
End Select
Wend
End With
Set oRng = Nothing
Selection.HomeKey wdStory
End Sub



i tired the technique you mentioned to the macros displayed below. I
m getting some error can you pls help me out

Sub ScratchMacro()
Dim oRng As Range
Dim rslt As VbMsgBoxResult
Set myRange = ActiveDocument.Range
With myRange.FInd
.Text = "<([A-Z]{2,})>"
.MatchWildcards = True
.Wrap = wdFindStop
.Forward = True
While .Execute
myRange.Select
If myRange.Text <> "TABLE" Then
If myRange.Text <> "OF" Then
If myRange.Text <> "RIO" Then
If myRange.Text <> "OST" Then
If myRange.Text <> "RLO" Then
If myRange.Text <> "NEXT" Then
If myRange.Text <> "CONTENTS" Then
If myRange.Text <> "AUDIO" Then
If myRange.Text <> "TEXT" Then
If myRange.Text <> "NOTE" Then
If myRange.Text <> "TIP" Then
If myRange.Text <> "MCQ" Then
If myRange.Text <> "WILL" Then
If myRange.Text <> "TRADE" Then
If myRange.Text <> "OR" Then
Set oRng = myRange.Duplicate
oRng.Move wdCharacter, -5
oRng.MoveEnd wdCharacter, 4
If Not oRng.Text = "the " Then
If Not oRng.Text = "The " Then
rslt = Msgbox(prompt:="Add 'the' before this acronym?", _
Buttons:=vbYesNoCancel & " The word " & oRng & " on page "
& Selection.Information(wdActiveEndPageNumber) & " is selected")
If rslt = vbCancel Then Exit Sub
If rslt = vbYes Then
Selection.InsertBefore "the "
myRange.Collapse wdCollapseEnd
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

End If
End If
End If
End If
myRange.Collapse wdCollapseEnd
Wend
End With
Set myRange = Nothing
End Sub
Sub ScratchMacro()
With ActiveDocument
MsgBox .Paragraphs.Last.Range.Text
.Range.InsertAfter "Yes macros can do undo actions"
MsgBox .Paragraphs.Last.Range.Text
ActiveDocument.Undo
MsgBox .Paragraphs.Last.Range.Text
End With
End Sub
 
D

Designingsally

thanks for tje reply.
--
I believe in Hope.

DesigningSally


Doug Robbins - Word MVP said:
Sometimes it is going to be a lot easier to help us if in addition to the
code that you are trying to use, you also tell us in plain English what you
are starting with and what you are trying to achieve.

If your code errors out. you should also indicate which line of code is
causing the error.

--
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, originally posted via msnews.microsoft.com
Designingsally said:
i tired the technique you mentioned to the macros displayed below. I m
getting some error can you pls help me out

Sub ScratchMacro()
Dim oRng As Range
Dim rslt As VbMsgBoxResult
Set myRange = ActiveDocument.Range
With myRange.FInd
.Text = "<([A-Z]{2,})>"
.MatchWildcards = True
.Wrap = wdFindStop
.Forward = True
While .Execute
myRange.Select
If myRange.Text <> "TABLE" Then
If myRange.Text <> "OF" Then
If myRange.Text <> "RIO" Then
If myRange.Text <> "OST" Then
If myRange.Text <> "RLO" Then
If myRange.Text <> "NEXT" Then
If myRange.Text <> "CONTENTS" Then
If myRange.Text <> "AUDIO" Then
If myRange.Text <> "TEXT" Then
If myRange.Text <> "NOTE" Then
If myRange.Text <> "TIP" Then
If myRange.Text <> "MCQ" Then
If myRange.Text <> "WILL" Then
If myRange.Text <> "TRADE" Then
If myRange.Text <> "OR" Then
Set oRng = myRange.Duplicate
oRng.Move wdCharacter, -5
oRng.MoveEnd wdCharacter, 4
If Not oRng.Text = "the " Then
If Not oRng.Text = "The " Then
rslt = Msgbox(prompt:="Add 'the' before this acronym?", _
Buttons:=vbYesNoCancel & " The word " & oRng & " on page " &
Selection.Information(wdActiveEndPageNumber) & " is selected")
If rslt = vbCancel Then Exit Sub
If rslt = vbYes Then
Selection.InsertBefore "the "
myRange.Collapse wdCollapseEnd
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

End If
End If
End If
End If
myRange.Collapse wdCollapseEnd
Wend
End With
Set myRange = Nothing
End Sub
--
I believe in Hope.

DesigningSally


Greg Maxey said:
Sub ScratchMacro()
With ActiveDocument
MsgBox .Paragraphs.Last.Range.Text
.Range.InsertAfter "Yes macros can do undo actions"
MsgBox .Paragraphs.Last.Range.Text
ActiveDocument.Undo
MsgBox .Paragraphs.Last.Range.Text
End With
End Sub
 
D

Designingsally

thanks greg. it helped me
--
I believe in Hope.

DesigningSally


Greg Maxey said:
The If statement should read:

If Not .Text = "the " And Not .Text = "The " Then

vice

If Not .Text = "the " Or Not .Text = "The " Then

Greg said:
I have to agree with what Doug has suggested. Still I took a stab at
what I thought you were after:

Sub ScratchMacro()
Dim oRng As Range
Dim oRngDup As Range
Dim rslt As VbMsgBoxResult
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "<([A-Z]{2,})"
.MatchWildcards = True
.Wrap = wdFindStop
.Forward = True
While .Execute
oRng.Select
Select Case oRng.Text
'Exclude first case words.
Case Is = "TABLE", "OF", "RIO", "OST", "RLO", "NEXT", "CONTENTS",
"AUDIO", "TEXT", _
"NOTE", "TIP", "MCQ", "WILL", "TRADE", "OR"
oRng.Collapse wdCollapseEnd
'Process all other words
Case Else
Set oRngDup = oRng.Duplicate
With oRngDup
.Move wdCharacter, -5
.MoveEnd wdCharacter, 4
If Not .Text = "the " Or Not .Text = "The " Then
Select Case MsgBox("Add " & Chr(34) & "the" & Chr(34) & "
before " & oRng & " on page " &
Selection.Information(wdActiveEndPageNumber) & "?", vbQuestion +
vbYesNoCancel, "Add artical?") Case vbCancel
Exit Sub
Case vbYes
oRng.InsertBefore "the "
oRng.Collapse wdCollapseEnd
End Select
End If
End With
End Select
Wend
End With
Set oRng = Nothing
Selection.HomeKey wdStory
End Sub



i tired the technique you mentioned to the macros displayed below. I
m getting some error can you pls help me out

Sub ScratchMacro()
Dim oRng As Range
Dim rslt As VbMsgBoxResult
Set myRange = ActiveDocument.Range
With myRange.FInd
.Text = "<([A-Z]{2,})>"
.MatchWildcards = True
.Wrap = wdFindStop
.Forward = True
While .Execute
myRange.Select
If myRange.Text <> "TABLE" Then
If myRange.Text <> "OF" Then
If myRange.Text <> "RIO" Then
If myRange.Text <> "OST" Then
If myRange.Text <> "RLO" Then
If myRange.Text <> "NEXT" Then
If myRange.Text <> "CONTENTS" Then
If myRange.Text <> "AUDIO" Then
If myRange.Text <> "TEXT" Then
If myRange.Text <> "NOTE" Then
If myRange.Text <> "TIP" Then
If myRange.Text <> "MCQ" Then
If myRange.Text <> "WILL" Then
If myRange.Text <> "TRADE" Then
If myRange.Text <> "OR" Then
Set oRng = myRange.Duplicate
oRng.Move wdCharacter, -5
oRng.MoveEnd wdCharacter, 4
If Not oRng.Text = "the " Then
If Not oRng.Text = "The " Then
rslt = Msgbox(prompt:="Add 'the' before this acronym?", _
Buttons:=vbYesNoCancel & " The word " & oRng & " on page "
& Selection.Information(wdActiveEndPageNumber) & " is selected")
If rslt = vbCancel Then Exit Sub
If rslt = vbYes Then
Selection.InsertBefore "the "
myRange.Collapse wdCollapseEnd
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

End If
End If
End If
End If
myRange.Collapse wdCollapseEnd
Wend
End With
Set myRange = Nothing
End Sub

Sub ScratchMacro()
With ActiveDocument
MsgBox .Paragraphs.Last.Range.Text
.Range.InsertAfter "Yes macros can do undo actions"
MsgBox .Paragraphs.Last.Range.Text
ActiveDocument.Undo
MsgBox .Paragraphs.Last.Range.Text
End With
End Sub
 
D

Designingsally

Doug

I make sure. Next time when I post I make my posts more detail and
comprehensive.
--
I believe in Hope.

DesigningSally


Doug Robbins - Word MVP said:
Sometimes it is going to be a lot easier to help us if in addition to the
code that you are trying to use, you also tell us in plain English what you
are starting with and what you are trying to achieve.

If your code errors out. you should also indicate which line of code is
causing the error.

--
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, originally posted via msnews.microsoft.com
Designingsally said:
i tired the technique you mentioned to the macros displayed below. I m
getting some error can you pls help me out

Sub ScratchMacro()
Dim oRng As Range
Dim rslt As VbMsgBoxResult
Set myRange = ActiveDocument.Range
With myRange.FInd
.Text = "<([A-Z]{2,})>"
.MatchWildcards = True
.Wrap = wdFindStop
.Forward = True
While .Execute
myRange.Select
If myRange.Text <> "TABLE" Then
If myRange.Text <> "OF" Then
If myRange.Text <> "RIO" Then
If myRange.Text <> "OST" Then
If myRange.Text <> "RLO" Then
If myRange.Text <> "NEXT" Then
If myRange.Text <> "CONTENTS" Then
If myRange.Text <> "AUDIO" Then
If myRange.Text <> "TEXT" Then
If myRange.Text <> "NOTE" Then
If myRange.Text <> "TIP" Then
If myRange.Text <> "MCQ" Then
If myRange.Text <> "WILL" Then
If myRange.Text <> "TRADE" Then
If myRange.Text <> "OR" Then
Set oRng = myRange.Duplicate
oRng.Move wdCharacter, -5
oRng.MoveEnd wdCharacter, 4
If Not oRng.Text = "the " Then
If Not oRng.Text = "The " Then
rslt = Msgbox(prompt:="Add 'the' before this acronym?", _
Buttons:=vbYesNoCancel & " The word " & oRng & " on page " &
Selection.Information(wdActiveEndPageNumber) & " is selected")
If rslt = vbCancel Then Exit Sub
If rslt = vbYes Then
Selection.InsertBefore "the "
myRange.Collapse wdCollapseEnd
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

End If
End If
End If
End If
myRange.Collapse wdCollapseEnd
Wend
End With
Set myRange = Nothing
End Sub
--
I believe in Hope.

DesigningSally


Greg Maxey said:
Sub ScratchMacro()
With ActiveDocument
MsgBox .Paragraphs.Last.Range.Text
.Range.InsertAfter "Yes macros can do undo actions"
MsgBox .Paragraphs.Last.Range.Text
ActiveDocument.Undo
MsgBox .Paragraphs.Last.Range.Text
End With
End Sub
 

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