Problem with simple macro

I am having a problem with a very simple macro. This may have something to do with other problems we are having with Office 365 programs. I stripped a one page document down to one line for testing.
The line reads as follows:

___ Home Office Deduction 75.XX Net Operating Losses 300.00

Placing the cursor at the beginning of the line I recorded a macro to find .XX and then put a space between the two XXs. Then jump to the end of the line.
Simple right?
No. The macro runs but puts the space at the beginning of the line.
I have recorded it multiple times, all with the same outcome.
I have attached the file for testing.
LVL 1
Bill GoldenExecutive Managing MemberAsked:
Who is Participating?
 
MacroShadowCommented:
You didn't record the search and replace.
Look at the code I posted, it is from a recording doing what you asked.
0
 
MacroShadowCommented:
This works for me:
Option Explicit

Sub Macro1()
    Selection.HomeKey Unit:=wdLine
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "XX"
        .Replacement.Text = "X X"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.EndKey Unit:=wdLine
End Sub

Open in new window

0
 
Bill GoldenExecutive Managing MemberAuthor Commented:
I guess I failed to define the goal. The macro we bill more extensive in the end. I am just trying to decide what I am doing wrong in that I cannot see to get a basic macro to work. Any thoughts?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
MacroShadowCommented:
Well, being as you haven't shown us your code, no, no thoughts.
0
 
Bill GoldenExecutive Managing MemberAuthor Commented:
Well, when I recorded the macro, Word produced the following code:

Sub Macro1()
'
' Macro1 Macro
'
'
    CommandBars("Navigation").Visible = False
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:=" "
    Selection.EndKey Unit:=wdLine
End Sub

Which of course is pure crap since it did not work. What I am trying to figure out is WHY?
0
 
Neil FlemingConsultant and developerCommented:
Hi Bill, as MacroShadow says, your code is not searching for the XX.

All that your code does is move one character to the right of whatever text is selected, then move one character left (for some reason), then types a space. Maybe you accidentally started recording after finding the XX.
0
 
Bill GoldenExecutive Managing MemberAuthor Commented:
I have discovered why the Macro was not recording the step. In performing the step, the find result is accomplished but you cannot X out of the step. If you do, the Macro does not include that function.

Thanks guys.
0
 
Bill GoldenExecutive Managing MemberAuthor Commented:
I have discovered why the Macro was not recording the step. In performing the step, the find result is accomplished but you cannot X out of the step. If you do, the Macro does not include that function.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.