Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Software Development Software Development
Search Search
Search for:
Tech Support Guy > > >

Macro Syntax error


(!)

mikefoxmikefox's Avatar
mikefoxmikefox mikefoxmikefox is offline
Computer Specs
Member with 3 posts.
THREAD STARTER
 
Join Date: Aug 2012
Experience: Intermediate
10-Aug-2012, 12:04 PM #1
Unhappy Macro Syntax error
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's Avatar
janikPilot   (Michael) janikPilot is offline
Computer Specs
Member with 141 posts.
 
Join Date: Nov 2010
Location: South FL
Experience: Advanced
11-Aug-2012, 01:52 PM #2
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
Code:
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's Avatar
ckphilli   (Chris) ckphilli is offline
Member with 4,244 posts.
 
Join Date: Apr 2006
Location: Down South
Experience: Intermediate
11-Aug-2012, 02:24 PM #3
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's Avatar
ckphilli   (Chris) ckphilli is offline
Member with 4,244 posts.
 
Join Date: Apr 2006
Location: Down South
Experience: Intermediate
11-Aug-2012, 02:48 PM #4
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.

Code:
Sub InsertRedLine()

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

End Sub
mikefoxmikefox's Avatar
mikefoxmikefox mikefoxmikefox is offline
Computer Specs
Member with 3 posts.
THREAD STARTER
 
Join Date: Aug 2012
Experience: Intermediate
13-Aug-2012, 09:58 AM #5
Quote:
Originally Posted by janikPilot View Post
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
Code:
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.
Many thanks for your prompt, informative and helpful reply.

Mike Fox.
mikefoxmikefox's Avatar
mikefoxmikefox mikefoxmikefox is offline
Computer Specs
Member with 3 posts.
THREAD STARTER
 
Join Date: Aug 2012
Experience: Intermediate
13-Aug-2012, 09:59 AM #6
Quote:
Originally Posted by ckphilli View Post
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
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


Tags
compile error, macro malfunctions

(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑