Range error Word 2007

J

jec

Hi, macro does not work in Word 2007? It throws a Range error? Works fine in Word 2003. The text is selected and range redacted. Any ideas please?

'Set rgeRedact = Selection.Range **** Compile error method or data member not found!

Sub TestMe1()

Dim rgeRedact As Range
Dim lngCount As Long
Dim i As Long

Set rgeRedact = Selection.Range '*** Compile error method or data member not found!

If Selection.Type = wdSelectionIP Then
MsgBox Prompt:="Please select some text to redact! Exiting macro..."
Exit Sub
Else

With rgeRedact
lngCount = .Characters.Count
For i = 1 To lngCount
If Asc(.Characters(i)) > 20 Then
.Characters(i).Text = "_"
End If
Next
.MoveEnd wdCharacter, 1
.HighlightColorIndex = wdBlack
End With

End If
End Sub
 
G

Graham Mayor

It works for me?

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


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



Hi, macro does not work in Word 2007? It throws a Range error? Works fine in Word 2003. The text is selected and range redacted. Any ideas please?

'Set rgeRedact = Selection.Range **** Compile error method or data member not found!

Sub TestMe1()

Dim rgeRedact As Range
Dim lngCount As Long
Dim i As Long

Set rgeRedact = Selection.Range '*** Compile error method or data member not found!

If Selection.Type = wdSelectionIP Then
MsgBox Prompt:="Please select some text to redact! Exiting macro..."
Exit Sub
Else

With rgeRedact
lngCount = .Characters.Count
For i = 1 To lngCount
If Asc(.Characters(i)) > 20 Then
.Characters(i).Text = "_"
End If
Next
.MoveEnd wdCharacter, 1
.HighlightColorIndex = wdBlack
End With

End If
End Sub
 
J

jec

That would be right! - It works in 2003 but in 2007 I've had issues. Although I am sure it worked last week!

Thank you
It works for me?

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


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



Hi, macro does not work in Word 2007? It throws a Range error? Works fine in Word 2003. The text is selected and range redacted. Any ideas please?

'Set rgeRedact = Selection.Range **** Compile error method or data member not found!

Sub TestMe1()

Dim rgeRedact As Range
Dim lngCount As Long
Dim i As Long

Set rgeRedact = Selection.Range '*** Compile error method or data member not found!

If Selection.Type = wdSelectionIP Then
MsgBox Prompt:="Please select some text to redact! Exiting macro..."
Exit Sub
Else

With rgeRedact
lngCount = .Characters.Count
For i = 1 To lngCount
If Asc(.Characters(i)) > 20 Then
.Characters(i).Text = "_"
End If
Next
.MoveEnd wdCharacter, 1
.HighlightColorIndex = wdBlack
End With

End If
End Sub
 
J

jec

I actually get in 2003 black redact text and now in 2007 I just get the ______ line.

Any ideas why that is?
It works for me?

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


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



Hi, macro does not work in Word 2007? It throws a Range error? Works fine in Word 2003. The text is selected and range redacted. Any ideas please?

'Set rgeRedact = Selection.Range **** Compile error method or data member not found!

Sub TestMe1()

Dim rgeRedact As Range
Dim lngCount As Long
Dim i As Long

Set rgeRedact = Selection.Range '*** Compile error method or data member not found!

If Selection.Type = wdSelectionIP Then
MsgBox Prompt:="Please select some text to redact! Exiting macro..."
Exit Sub
Else

With rgeRedact
lngCount = .Characters.Count
For i = 1 To lngCount
If Asc(.Characters(i)) > 20 Then
.Characters(i).Text = "_"
End If
Next
.MoveEnd wdCharacter, 1
.HighlightColorIndex = wdBlack
End With

End If
End Sub
 
G

Graham Mayor

Why do you need the underscore? All you appear to be doing is changing one
character more than a selected a block of text to black highlight - unless
you need the extra length of the underscore character?

The following would do that

With rgeRedact
.MoveEnd wdCharacter, 1
.HighlightColorIndex = wdBlack
End With


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


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


"jec" <[email protected] wrote in message (e-mail address removed)...
I actually get in 2003 black redact text and now in 2007 I just get the
______ line.
 
J

jec

Yes, so does below (I just tried):

..Font.Shading.BackgroundPatternColor = WdColor.wdColorBlack
..Font.Color = word.WdColor.wdColorBlack

It is the pilcrows that present a problem - but in 2007 it just does
underscores as it is.

I'll keep testing...

Thanks Graham
 
G

Graham Mayor

Pilcrows? Do you mean the paragraph end characters? How do they affect the
issue? What *exactly* is it that you are trying to achieve.

I have had no problems with any of this code in 2007.

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


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

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