# Macro Syntax error



## mikefoxmikefox (Aug 10, 2012)

I am using Word 2007 on my Dell PC/WXP (Home). I have been using computers for over twenty-years and made a few simple macros as directed by the program instructions. I lost them all recently and have reconfigured some. But they appear in some documents and not in others. I have repeated the procedure as I closely as I can get to perfect (my knowledge of computer technics - rather than usage - is absolutely basic). On copying a recommended macro off an internet website, I pasted it in and when trying to use it get an error message, as follows:

*MICROSOFT VISUAL BASIC*

*Compile error*

*Syntax error*

The said macro, cut and pasted is:

Sub InsertRedLine()
'
' InsertRedLine Macro
' Macro recorded 03/12/03 by Mike Fox
'
Selection.InlineShapes.AddHorizontalLineStandard
Selection.Font.Color = wdColorRed
Selection.InlineShapes.AddHorizontalLineStandard
End Sub

Can anyone explain what the syntax error is and how I can change it to make it work?

Also, I have checlked my security settings and allowed all macros to function. Despite this, on clicking on a macro button an error message appears saying that my macro 'cannot be found or has been disabled'.

I am truly perplexed by the complications of all this...

Would be grateful for help and advice.


----------



## janikPilot (Nov 26, 2010)

A syntax error is something wrong with the code that prevents the computer from understanding it. Think of it as a computer version of a grammar error.

I would suggest removing the second instance of

```
Selection.InlineShapes.AddHorizontalLineStandard
```
Since it does nothing the second time, as nothing follows it.

Then try compiling it again. The error of it not being able to run is caused by a failed compilation, which was due to the syntax error.


----------



## ckphilli (Apr 29, 2006)

It adds a second line, so that isn't the problem janikPilot.

I was able to get the macro to work with no issues except for the line coloring.


@ mikefoxmikefox , it might help if you posted what you are seeing in the macro editor. I suspect you have some extra codes\ on your machine.


----------



## ckphilli (Apr 29, 2006)

Ok, got the color working. The code below makes 1 red line.

mikefoxmikefox, if you click macros, then make sure you have 'all active templates and documents', click create, paste the code below at the end, and you should be in business.


```
Sub InsertRedLine()

    Dim testInsert As Object
    Set testInsert = Selection.InlineShapes.AddHorizontalLineStandard
        testInsert.Fill.ForeColor.RGB = 255

End Sub
```


----------



## mikefoxmikefox (Aug 10, 2012)

janikPilot said:


> A syntax error is something wrong with the code that prevents the computer from understanding it. Think of it as a computer version of a grammar error.
> 
> I would suggest removing the second instance of
> 
> ...


Many thanks for your prompt, informative and helpful reply.

Mike Fox.


----------



## mikefoxmikefox (Aug 10, 2012)

ckphilli said:


> It adds a second line, so that isn't the problem janikPilot.
> 
> I was able to get the macro to work with no issues except for the line coloring.
> 
> @ mikefoxmikefox , it might help if you posted what you are seeing in the macro editor. I suspect you have some extra codes\ on your machine.


Many thanks for your helpful advice.

Mike Fox


----------

