Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Wed, 4 Jun 2008 14:54:15 -0600,    group: microsoft.public.word.vba.beginners        back       


Beginner question   
I'm using Word 2003 on a Vista Business box.  I've tried to duplicate a 
macro shown in VBA for Dummies 4th Edition to remove highlighting of text. 
I'm searching for yellow highlighting and want to simply remove it.  Where 
have I gone wrong - I keep getting a 91 error regarding the line "With 
DoSearch" at top of repeated code section.

Macro follows:===================================================
Public Sub RemoveHighlight()
'
' RemoveHighlight Macro

Dim CurrPane As Pane
' ActiveDocument.ActiveWindow.View = wdNormalView

CurrPane.Selection.GoTo wdGoToLine, wdGoToFirst
Dim DoSearch As Find
Set DoSearch = CurrPane.Selection.Find
    With DoSearch
        .ClearFormatting
        .Highlight = True
        .MatchCase = False
        While DoSearch.Execute()
            With CurrPane.Selection.FormattedText
                If .HighlightColorIndex = wdYellow Then
                   .HighlightColorIndex = wdNoHighlight
                End If
            End With
        Wend
    CurrPane.Selection.GoTo wdGoToLine, wdGoToFirst
    End With
End Sub


=======================================
Thanks!
Jim
James L Szatkowski, PE, NSPE
jamesski@jlsce.com
http://www.jlsce.com
date: Wed, 4 Jun 2008 14:54:15 -0600   author:   Jim Szatkowski

Re: Beginner question   
The error occurs on the CurrPane.Selection.GoTo, not on the With DoSearch. The
error's text is "Object variable or With block variable not set", and what it's
trying to tell you is that you declared the variable CurrPane but you never
assigned a value to it. Since that object variable doesn't have a value, you
can't use any of its members.

To verify this, run the macro by putting the cursor in the code in the VBA
editor and executing one statement at a time by pressing F8. Notice which
statement is highlighted when the error occurs.

You can make the macro work by inserting this line in place of the commented-out
ActiveDocument.ActiveWindow statement:

   Set CurrPane = ActiveWindow.ActivePane

As you learn more VBA, you'll learn that it's better to use a Range object
instead of the Selection object in applications like this... but that's another
subject. :-)

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.

On Wed, 4 Jun 2008 14:54:15 -0600, "Jim Szatkowski"  wrote:

>I'm using Word 2003 on a Vista Business box.  I've tried to duplicate a 
>macro shown in VBA for Dummies 4th Edition to remove highlighting of text. 
>I'm searching for yellow highlighting and want to simply remove it.  Where 
>have I gone wrong - I keep getting a 91 error regarding the line "With 
>DoSearch" at top of repeated code section.
>
>Macro follows:===================================================
>Public Sub RemoveHighlight()
>'
>' RemoveHighlight Macro
>
>Dim CurrPane As Pane
>' ActiveDocument.ActiveWindow.View = wdNormalView
>
>CurrPane.Selection.GoTo wdGoToLine, wdGoToFirst
>Dim DoSearch As Find
>Set DoSearch = CurrPane.Selection.Find
>    With DoSearch
>        .ClearFormatting
>        .Highlight = True
>        .MatchCase = False
>        While DoSearch.Execute()
>            With CurrPane.Selection.FormattedText
>                If .HighlightColorIndex = wdYellow Then
>                   .HighlightColorIndex = wdNoHighlight
>                End If
>            End With
>        Wend
>    CurrPane.Selection.GoTo wdGoToLine, wdGoToFirst
>    End With
>End Sub
>
>
>=======================================
>Thanks!
>Jim
>James L Szatkowski, PE, NSPE
>jamesski@jlsce.com
>http://www.jlsce.com
date: Wed, 04 Jun 2008 20:14:08 -0400   author:   Jay Freedman

RE: Beginner question   
"Jim Szatkowski" wrote:

> I'm using Word 2003 on a Vista Business box.  I've tried to duplicate a 
> macro shown in VBA for Dummies 4th Edition to remove highlighting of text. 
> I'm searching for yellow highlighting and want to simply remove it.  Where 
> have I gone wrong - I keep getting a 91 error regarding the line "With 
> DoSearch" at top of repeated code section.
> 

I hope Jay has answered your query...

Meanwhile... I was curious about something. Was the code you posted lifted 
directly from the book? I would be curious to see the original code in the 
book...
date: Thu, 5 Jun 2008 05:24:03 -0700   author:   Jean-Guy Marcil

Re: Beginner question   
Jean-Guy:

The original code is at 
http://media.wiley.com/assets/1312/51/VBAforDummiesSourceCode.zip  Go to 
Chapter 13 listings.

FYI
Jim

"Jean-Guy Marcil"  wrote in message 
news:D7C03D2C-A3DD-46B7-AA51-D3A01DFF80C6@microsoft.com...
> "Jim Szatkowski" wrote:
>
>> I'm using Word 2003 on a Vista Business box.  I've tried to duplicate a
>> macro shown in VBA for Dummies 4th Edition to remove highlighting of 
>> text.
>> I'm searching for yellow highlighting and want to simply remove it. 
>> Where
>> have I gone wrong - I keep getting a 91 error regarding the line "With
>> DoSearch" at top of repeated code section.
>>
>
> I hope Jay has answered your query...
>
> Meanwhile... I was curious about something. Was the code you posted lifted
> directly from the book? I would be curious to see the original code in the
> book...
>
date: Thu, 5 Jun 2008 13:05:46 -0600   author:   Jim Szatkowski

Re: Beginner question   
Worked!  Thanks!!
Jim
"Jay Freedman"  wrote in message 
news:7fbe44tg7d177cmeecrnjhp0neqsu887ic@4ax.com...
> The error occurs on the CurrPane.Selection.GoTo, not on the With DoSearch. 
> The
> error's text is "Object variable or With block variable not set", and what 
> it's
> trying to tell you is that you declared the variable CurrPane but you 
> never
> assigned a value to it. Since that object variable doesn't have a value, 
> you
> can't use any of its members.
>
> To verify this, run the macro by putting the cursor in the code in the VBA
> editor and executing one statement at a time by pressing F8. Notice which
> statement is highlighted when the error occurs.
>
> You can make the macro work by inserting this line in place of the 
> commented-out
> ActiveDocument.ActiveWindow statement:
>
>   Set CurrPane = ActiveWindow.ActivePane
>
> As you learn more VBA, you'll learn that it's better to use a Range object
> instead of the Selection object in applications like this... but that's 
> another
> subject. :-)
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP        FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup 
> so all
> may benefit.
>
> On Wed, 4 Jun 2008 14:54:15 -0600, "Jim Szatkowski"  
> wrote:
>
>>I'm using Word 2003 on a Vista Business box.  I've tried to duplicate a
>>macro shown in VBA for Dummies 4th Edition to remove highlighting of text.
>>I'm searching for yellow highlighting and want to simply remove it.  Where
>>have I gone wrong - I keep getting a 91 error regarding the line "With
>>DoSearch" at top of repeated code section.
>>
>>Macro follows:===================================================
>>Public Sub RemoveHighlight()
>>'
>>' RemoveHighlight Macro
>>
>>Dim CurrPane As Pane
>>' ActiveDocument.ActiveWindow.View = wdNormalView
>>
>>CurrPane.Selection.GoTo wdGoToLine, wdGoToFirst
>>Dim DoSearch As Find
>>Set DoSearch = CurrPane.Selection.Find
>>    With DoSearch
>>        .ClearFormatting
>>        .Highlight = True
>>        .MatchCase = False
>>        While DoSearch.Execute()
>>            With CurrPane.Selection.FormattedText
>>                If .HighlightColorIndex = wdYellow Then
>>                   .HighlightColorIndex = wdNoHighlight
>>                End If
>>            End With
>>        Wend
>>    CurrPane.Selection.GoTo wdGoToLine, wdGoToFirst
>>    End With
>>End Sub
>>
>>
>>=======================================
>>Thanks!
>>Jim
>>James L Szatkowski, PE, NSPE
>>jamesski@jlsce.com
>>http://www.jlsce.com
date: Thu, 5 Jun 2008 13:51:58 -0600   author:   Jim Szatkowski

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us