+ Reply to Thread
Results 1 to 9 of 9

Bad Syntax for calling public variables

  1. #1
    Forum Contributor
    Join Date
    08-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    132

    Bad Syntax for calling public variables

    I'm incredibly close to getting a couple of different things to work together well, but I'm doing something wrong that is probably pretty simple.

    I have a macrobook that has two buttons which call macros. The first to select a workbook, and the second to select a macro. The workbook shows to the user in the following way:

    DW1.png

    The workbook they select ends up as a text string in B6, while the macro they wish to run on that book ends up in B9.

    I am now trying to put a third macro together that runs the selected macro on the selected workbook, using the following code:

    Outside of the function I have:

    Please Login or Register  to view this content.
    and the third button links to this:

    Please Login or Register  to view this content.
    This doesn't work at all. I understand HOW it's supposed to work, but I don't know how to code it correctly. My ultimate goal is to have this sub activate the selected Workbook, then execute the selected macro.

    Ideas?

  2. #2
    Registered User
    Join Date
    08-11-2013
    Location
    leeds
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Bad Syntax for calling public variables

    if you step through (F8) does the variable stepone populate properly, if not try StepOne = Thisworkbook.sheets(1).range("b6").value

    then i think you want workbooks(stepone).activate
    Last edited by notreallyIT; 12-04-2013 at 03:21 PM.

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Bad Syntax for calling public variables

    Hi, lordterrin,

    maybe like this (although I donīt know whatīs exactly the contents of the cell):
    Please Login or Register  to view this content.
    Sorry I donīt see the use of using public variables for this example.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Bad Syntax for calling public variables

    Why are you using public variables?

    You could just refer back to the values in the cells in the macrobook.
    If posting code please use code tags, see here.

  5. #5
    Forum Contributor
    Join Date
    08-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: Bad Syntax for calling public variables

    I was originally using StepOne and StepTwo across multiple functions - which is why I needed to use public variables.

    What you guys have suggested so far works for StepOne:

    Please Login or Register  to view this content.
    However, StepTwo - which calls the macro, still does not work. I get an "Invalid Use of Property" error.

    I guess my syntax on this is still bad - I use the Call feature in other parts in my book, and the word after "Call" is always the name of the function it's calling. However, in this instance, I'm asking it to call a variable name - so, not sure how to get that to work.

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Bad Syntax for calling public variables

    Hi, lordterrin,

    maybe there are more procedures of teh given name so the module should be provided as well as the workbook name?

    Ciao,
    Holger

  7. #7
    Forum Contributor
    Join Date
    08-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: Bad Syntax for calling public variables

    Hi Holger,

    I'm not sure how to do that.

    I got the correct VALUE in there by doing:

    Please Login or Register  to view this content.
    and if I use a MsgBox, the value is correct - I just don't know how to CALL it now as a function. I just have it in a string...

  8. #8
    Forum Contributor
    Join Date
    08-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: Bad Syntax for calling public variables

    Okay - it works with

    Please Login or Register  to view this content.
    Thanks everyone!

  9. #9
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Bad Syntax for calling public variables

    Correct me if I'm wrong, but it looks like you're trying to "Call" a range? I don't believe you can Call a range. Try something like this? (untested)

    Please Login or Register  to view this content.
    You may need to reference your workbook name

    Please Login or Register  to view this content.
    Again, untested and may need tweaking to get the syntax perfect, but the principle behind it is sound

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Calling a Public Loop
    By justforthis1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2012, 02:56 PM
  2. Calling a public function from userform
    By BBQNJL in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-09-2009, 05:38 PM
  3. Calling a DLL from Excel.:public domain
    By Jim15 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2007, 02:40 PM
  4. Calling a Public Subroutine in a Different Workbook
    By Raul in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-24-2005, 12:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1