+ Reply to Thread
Results 1 to 4 of 4

Passing variables in cells to macros

  1. #1
    Registered User
    Join Date
    09-18-2012
    Location
    Leiden, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    3

    Passing variables in cells to macros

    Hi all,

    I have a very simple function showing the duration of external audio files:

    Please Login or Register  to view this content.
    I can call the function like this:
    Please Login or Register  to view this content.
    where D:\Temp is the path and A1 refers to a cell containing the file name.

    This works too.

    However when I replace "D:\Temp" with prefix (the name of a cell containing the same text), things go wrong and I get #VALUE! instead. I think this has to do with the \, but I'm not sure.

    I'd like to be able to call the function like:

    Please Login or Register  to view this content.
    Any suggestions?

  2. #2
    Registered User
    Join Date
    09-18-2012
    Location
    Leiden, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Passing variables in cells to macros

    No one knows?

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Passing variables in cells to macros

    It's not the kind of programming I do, so I don't understand why this would be so. When you pass an cell to a UDF, the default is to pass it by reference. When the argument is a variant data type, this usually means that the variable essentially becomes a range object specifying that particular cell. Most of the time, when we use the argument name, VBA can correctly assume that we mean "the value contained in cell argument." In this case, I'm not sure that is true. I tried something that recognized the arguments as "range objects" then used the value property to explicitly tell VBA to use the value of the cell.
    Please Login or Register  to view this content.
    This seemed to work for me.

  4. #4
    Registered User
    Join Date
    09-18-2012
    Location
    Leiden, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Passing variables in cells to macros

    I'm sorry, I completely overlooked this answer. Thank you very much, MrShorty!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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