P
Paul B
Hi. I'm trying to figure out why this macro will step through ok,
but chokes when run (via F5 in the VBA app, or via hotkey in
Word.
Word says that the x variable doesn't exist. If you examine the
code, take note that it's the second instance of this variable
that's causing the problem. I had to recount the smarttags
because of the new Selection. Word counts the x correctly on
step-through, but not on Run. Maybe it just goes too fast on Run?
Here's the code. It probably looks a bit kludgy, but it isolates
a smarttag, executes it, then formats the pasted text, so there
are a lot of whizbangs.
Any insight would be appreciated.
p.
Sub LogosSmartTag()
' execute smarttag immediately preceding
' select line, cursor at line's end
Selection.HomeKey unit:=wdLine, Extend:=wdMove
Selection.EndKey unit:=wdLine, Extend:=wdExtend
myrange = Selection.Range
' With myrange
x = Selection.Range.SmartTags.Count
' End With
y = ActiveDocument.Paragraphs.Count
ActiveDocument.SmartTags(x).Select
Selection.Collapse wdCollapseStart
Selection.TypeParagraph
Selection.EndKey unit:=wdLine, Extend:=wdExtend
HERE'S WHERE THE RUNTIME ERROR HAPPENS.
5941: OBJECT DOESN'T EXIST
THIS REFERS TO THE "x" VARIABLE
x = Selection.SmartTags.Count
Selection.SmartTags(x).SmartTagActions(4).Execute
yy = ActiveDocument.Paragraphs.Count
y = yy - y
' merge citation to last verse
Selection.MoveDown unit:=wdParagraph, Count:=y - 1,
Extend:=wdMove
Selection.TypeBackspace
Selection.TypeText Text:=" "
' apply verse style
Selection.EndKey unit:=wdLine, Extend:=wdMove
With myrange
Selection.MoveUp unit:=wdParagraph, Count:=y - 1,
Extend:=wdExtend
Selection.Style = ActiveDocument.Styles("verse")
Selection.MoveDown unit:=wdParagraph, Count:=1,
Extend:=wdMove
End With
' resume text body style
Selection.TypeParagraph
Selection.Style = ActiveDocument.Styles("text body")
End Sub
but chokes when run (via F5 in the VBA app, or via hotkey in
Word.
Word says that the x variable doesn't exist. If you examine the
code, take note that it's the second instance of this variable
that's causing the problem. I had to recount the smarttags
because of the new Selection. Word counts the x correctly on
step-through, but not on Run. Maybe it just goes too fast on Run?
Here's the code. It probably looks a bit kludgy, but it isolates
a smarttag, executes it, then formats the pasted text, so there
are a lot of whizbangs.
Any insight would be appreciated.
p.
Sub LogosSmartTag()
' execute smarttag immediately preceding
' select line, cursor at line's end
Selection.HomeKey unit:=wdLine, Extend:=wdMove
Selection.EndKey unit:=wdLine, Extend:=wdExtend
myrange = Selection.Range
' With myrange
x = Selection.Range.SmartTags.Count
' End With
y = ActiveDocument.Paragraphs.Count
ActiveDocument.SmartTags(x).Select
Selection.Collapse wdCollapseStart
Selection.TypeParagraph
Selection.EndKey unit:=wdLine, Extend:=wdExtend
HERE'S WHERE THE RUNTIME ERROR HAPPENS.
5941: OBJECT DOESN'T EXIST
THIS REFERS TO THE "x" VARIABLE
x = Selection.SmartTags.Count
Selection.SmartTags(x).SmartTagActions(4).Execute
yy = ActiveDocument.Paragraphs.Count
y = yy - y
' merge citation to last verse
Selection.MoveDown unit:=wdParagraph, Count:=y - 1,
Extend:=wdMove
Selection.TypeBackspace
Selection.TypeText Text:=" "
' apply verse style
Selection.EndKey unit:=wdLine, Extend:=wdMove
With myrange
Selection.MoveUp unit:=wdParagraph, Count:=y - 1,
Extend:=wdExtend
Selection.Style = ActiveDocument.Styles("verse")
Selection.MoveDown unit:=wdParagraph, Count:=1,
Extend:=wdMove
End With
' resume text body style
Selection.TypeParagraph
Selection.Style = ActiveDocument.Styles("text body")
End Sub