Link to home
Start Free TrialLog in
Avatar of Bill Golden
Bill GoldenFlag for United States of America

asked on

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.
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

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

Avatar of Bill Golden

ASKER

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?
Well, being as you haven't shown us your code, no, no thoughts.
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?
ASKER CERTIFIED SOLUTION
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.