Advice re Insertion Point

K

kaprivi

I have a macro which toggles the "White Text on Blue Background"
on/off. To make sure I can read the text, I ensure that the font colour
for all text in the document is set to "automatic", however the method
I use to do this moves the insertion point to the beginning of the
document. I would like to re-position the insertion point at its
original location

I imagine that I should programmatically extract the initial location
of the insertion point, as I do in the example below, and then feed it
back into the programme when the font colour has been corrected.

I have placed some code below which I'd hoped might do the trick, but
it doesn't work. Does anyone have any suggestions?

Thanks in advance...

Sub Blue()

Dim lCol As Long
Dim lLine As Long
'extract original location of insertion point
lLine = Selection.Information(wdFirstCharacterLineNumber) - 1
lCol = Selection.Information(wdFirstCharacterColumnNumber) - 1

With Options
If .BlueScreen = False Then
Selection.WholeStory
Selection.Font.Color = wdColorAutomatic
Selection.MoveLeft Unit:=wdCharacter, Count:=1
' the commented code below gives a "bad parameter" error
' Selection.MoveDown Unit:=wdCharacter, Count:=lLine
' Selection.MoveRight Unit:=wdCharacter, Count:=lCol
.BlueScreen = True
Else
.BlueScreen = False
End If
End With
End Sub
 
H

Helmut Weber

Hi,

you don't need the selection at all, just this:

ActiveDocument.Range.Font.Color = wdColorAutomatic

if it's only about the mainstory, of course.
 
G

Greg

Use a range instead of a the selection.

Sub Test()
Dim myRng As Range
Set myRng = ActiveDocument.Range
With Options
If .BlueScreen = False Then
myRng.Font.Color = wdColorAutomatic
.BlueScreen = True
Else
.BlueScreen = False
End If
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