![]() |
#1
|
|||
|
|||
![]()
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 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
the character "v" when typed acts like ctrl-v. | jim redfield | Word | 1 | 09-22-2012 05:19 AM |
Wierd symbols inplace of "space", "indentation" etc | aka.bhagvanji | Word | 5 | 02-16-2012 11:50 AM |
Conditional formatting - "From" - Why does it recognise only names and not emails | ghumdinger | Outlook | 0 | 09-18-2011 01:28 AM |
![]() |
Jamal NUMAN | Word | 1 | 07-06-2011 04:25 AM |