1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Macro Syntax error

Discussion in 'Software Development' started by mikefoxmikefox, Aug 10, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. mikefoxmikefox

    mikefoxmikefox Thread Starter

    Joined:
    Aug 10, 2012
    Messages:
    3
    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.
     
  2. janikPilot

    janikPilot

    Joined:
    Nov 26, 2010
    Messages:
    141
    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.
     
  3. ckphilli

    ckphilli

    Joined:
    Apr 29, 2006
    Messages:
    4,384
    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.
     
  4. ckphilli

    ckphilli

    Joined:
    Apr 29, 2006
    Messages:
    4,384
    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
    
     
  5. mikefoxmikefox

    mikefoxmikefox Thread Starter

    Joined:
    Aug 10, 2012
    Messages:
    3
    Many thanks for your prompt, informative and helpful reply.

    Mike Fox.
     
  6. mikefoxmikefox

    mikefoxmikefox Thread Starter

    Joined:
    Aug 10, 2012
    Messages:
    3
    Many thanks for your helpful advice.

    Mike Fox
     
  7. Sponsor

As Seen On
As Seen On...

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.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1064591