Macro Error

G

Guest

In Word 2007, I created a macro which had an error in it. I therefore deleted
it, and re-recorded it with a new name. This macro works OK. The incorrect
macro does not now appear in the list of macros. However, every time I start
Word I get this error message:
Runtime error '91'. Object variable or With block variable not set.

How can I prevent this message from appearing?
Thank you
 
H

Herb Tyson [MVP]

Is there a Debug button in the error box? If so, click it and it should show
you where the error is. (I would suspect that the previously errant macro
was only partially deleted, and some remnant is causing the problem.)
 
G

Guest

Herb Tyson said:
Is there a Debug button in the error box? If so, click it and it should show
you where the error is. (I would suspect that the previously errant macro
was only partially deleted, and some remnant is causing the problem.)

--
Herb Tyson MS MVP
Author of the Word 2007 Bible
Blog: http://word2007bible.herbtyson.com
Web: http://www.herbtyson.com




I can't seem to fix the problem even in 'debug'. How can I delete the macro permanently?
 
G

Guest

Yes, it is highlighted. It reads:
With Selection.Find.Replacement.ParagraphFormat

I'm afraid I don't know what this means!
 
H

Herb Tyson [MVP]

Is that line contained within an existing macro? Or, does it look like it's
an orphaned line from a macro that was only partially deleted? The error
message you're seeing suggests that the With... construction might be
missing an End With statement... there might be a missing End Sub statement,
as well.

I would look above that line to see where the macro starts, then below it to
see where/if it ends. It's beginning to sound like you'll get more concise
help in one of the .vba newsgroups.

--
Herb Tyson MS MVP
Author of the Word 2007 Bible
Blog: http://word2007bible.herbtyson.com
Web: http://www.herbtyson.com
 
G

Guest

THis is the whole macro:
Sub MAIN()
'
' AutoExec.MAIN Macro
'
With Selection.Find.Replacement.Paragraph Format
' RemoveTwoParaMarks Macro
' Remove 2 para marks replace with one para mark format 12 pt spacing after
'


.SpaceBeforeAuto = False
.SpaceAfter = 12
.SpaceAfterAuto = False
.LineUnitAfter = 0
End With
With Selection.Find
.Text = "^p^p"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

What should be altered?
 
G

Graham Mayor

Change it to:

Sub RemoveTwoParaMarks()
' RemoveTwoParaMarks Macro
' Remove 2 para marks replace with one para mark format 12 pt spacing after

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^13{1,}"
.Replacement.Text = "^p"
.Replacement.ParagraphFormat.SpaceAfter = 12
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute replace:=wdReplaceAll
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Guest

Thank you. It worked!

Graham Mayor said:
Change it to:

Sub RemoveTwoParaMarks()
' RemoveTwoParaMarks Macro
' Remove 2 para marks replace with one para mark format 12 pt spacing after

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^13{1,}"
.Replacement.Text = "^p"
.Replacement.ParagraphFormat.SpaceAfter = 12
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute replace:=wdReplaceAll
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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