none
Passing parameters to a macro using the macrobutton RRS feed

  • Question

  • Hi Cindy,

    I was now working on another project and tried the macrobutton, but I'm Affraid that is no option. From my macro, I open a textfile, using a parameter to get the correct data.

    The data are in a table, with a title in the first column, the text in the second column and an image in the third (the image is not really there, only the complete path and filename).

    By calling MyMacro X (X being a variable of the Long-type)  I can open the correct row in the table.

    I don't think it is posible to add that variable in the macrobutton, or am I mistaking?

    Tuesday, June 30, 2015 9:21 AM

Answers

  • Hi Cindy,

    Thank you for your effort (again). Last night I found a solution.

    I used ActiveX commandbuttons to call the macro Sub GetHelp(ID as Long). So a macrocall would look like this: GetHelp 6 to call the helptext with ID 6.

     It is possible to insert a sort of parameter, but one will have to insert a private field into the macro like this:

    {{ private 6 } MACROBUTTON GetHelp "click for help"}. In the macro, you can then get the parameter like this:

    MyString = Selection.Fields(2).Code, so that MyString would be " private 6 " (you will have a leading and a trailing space).

    So the helpID would be val(Mid$(MyString,9)) (9 because of the leading space)

    this is a bit of a work-around, but it makes it possible to use a value in your macro, so the result is the same as when you use a parameter.

    As I am typing this, I realize that part of this thread should be in another thread, since it covers a completely different subject. Do you know if it is possible to move part of our discussion?

    Thanks again for your effort and especially for your quick replies.


    Wednesday, July 1, 2015 6:06 AM

All replies

  • Hi Han

    Mmmm. From where would the information come that should be passed as an argument to MyMacro? It's not possible to pass a parameter but the macro should be able to pick up the information from somewhere? Would you expect the user to type it into a control, into a bookmark, make a selection in the table containing the data, or...?


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, June 30, 2015 3:44 PM
    Moderator
  • Hi Cindy,

    Thank you for your effort (again). Last night I found a solution.

    I used ActiveX commandbuttons to call the macro Sub GetHelp(ID as Long). So a macrocall would look like this: GetHelp 6 to call the helptext with ID 6.

     It is possible to insert a sort of parameter, but one will have to insert a private field into the macro like this:

    {{ private 6 } MACROBUTTON GetHelp "click for help"}. In the macro, you can then get the parameter like this:

    MyString = Selection.Fields(2).Code, so that MyString would be " private 6 " (you will have a leading and a trailing space).

    So the helpID would be val(Mid$(MyString,9)) (9 because of the leading space)

    this is a bit of a work-around, but it makes it possible to use a value in your macro, so the result is the same as when you use a parameter.

    As I am typing this, I realize that part of this thread should be in another thread, since it covers a completely different subject. Do you know if it is possible to move part of our discussion?

    Thanks again for your effort and especially for your quick replies.


    Wednesday, July 1, 2015 6:06 AM
  • Hi Han

    It is certainly possible for me to split off branches of a discussion into a new thread. What would you like to do?


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, July 1, 2015 4:29 PM
    Moderator
  • Hi Cindy,

    i think it would be better to split off the messages from June 30 until now and put them in a separate thread, called "passing parameters to a macro using the macrobutton".

    Friday, July 3, 2015 7:15 AM