View Single Post
 
Old 10-03-2013, 10:16 AM
Dart82 Dart82 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Oct 2013
Posts: 7
Dart82 is on a distinguished road
Default Conditional tied to trying to find a " " space character

Hey, I'm trying to write MS word VBA code to find a space to the left of the cursor. If the space is found, go to right of the space, otherwise, type a space. I've also attached an image to try to be more specific.


My code assumes I start to the left of the required location. I then select the text one character to the left. I search this text for a " ". However, I can't get it to work correctly.

Could anybody please help me get my code, shown below, sorted?
Code:
Sub IfSpaceFound()
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    With Selection.Find
        .ClearFormatting
        .Text = " "
        .Forward = True
        .Wrap = False
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute
        If .Found
            Selection.MoveRight Unit:=wdCharacter, Count:=1
        Else
            Selection.TypeText Text:=" "
        End If
    End With
End Sub
Attached Images
File Type: png 2013-10-03_130946.png (2.7 KB, 32 views)
Reply With Quote