+ Reply to Thread
Results 1 to 8 of 8

Trying to link a variable to a public const

  1. #1
    Registered User
    Join Date
    09-06-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Trying to link a variable to a public const

    I have a list of file directories located on a second module using public const (I think this is a way to house the data?). On Module #1 I have a macro that has a prompt to enter text into an inputbox. Inside the inputbox I will be entering a name ie Andy. I would like to make a new variable that looks up Andy on the public const & defind that variable as the file directory for Andy. I am basically trying to automate saving an excel doc as a PDF to a specific folder base on the name I type into the inputbox. Can someone please help? Below are the macros I have now



    Module #1

    Please Login or Register  to view this content.

    Module #2

    Please Login or Register  to view this content.
    Last edited by ttd; 09-26-2012 at 11:45 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Trying to link a variable to a public const

    Hello there,

    Can you please add code tags around you post? Also, what values will be entered into the text box? For instance what is entered into the textbox to make the variable location equal to Public Const Tim= "G:\Users\Tim\" and so on?

    Thanks!

  3. #3
    Registered User
    Join Date
    09-06-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Trying to link a variable to a public const

    I will be entering a client name into the inputbox & using that name in the save as string (saving the pdf as "client name 1/2/3/4 Q Account Overview". So basically, the client name I type into the inputbox has two functions. 1. used in save as string and 2. used to determine which file location that client should be saved to based on the public const I set up for each client. Each client has a different file location (separate folder) & I am trying to be able to type just a client name & my macro will save it in the correct folder. Thanks

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

    Re: Trying to link a variable to a public const

    As structured, I'm thinking a Select Case statement might be the easiest to program:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-06-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Trying to link a variable to a public const

    Thank you. I have over 100 client folders so will that many case statements slow down the macro? I guess there really isn't a better way to store these directories in the module.

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

    Re: Trying to link a variable to a public const

    I don't know how that many cases will effect performance.

    There might be -- I'm not sure of your reasons for storing these values in constants. If I were doing this, I might try storing the directory names in a lookup table in a spreadsheet or in an array (I don't think constants can store arrays. If I'm wrong someone correct me). Then you could use some kind of lookup statement to return the directory string. There might be performance penalties for building the array or referencing the worksheet, too, so I'm not sure if this is better or just different.

  7. #7
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Trying to link a variable to a public const

    Try this instead

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    09-06-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Trying to link a variable to a public const

    This macro is inside an add-in and I run it on individual client's spreadsheets so I cannot house the file locations string inside a central spreadsheet because I run this macro on tons of indivdual spreadsheets. Each client has a performance report saved in their own client folder. I open each file separately & audit the data then run the macro to save a file verison as a pdf.

    Each client's folder location is unique so I cannot use Location = "G:\Users\" & MyInput & "\"

    I finished entering all the file locations to the macro & it run quick so all good.

    Thanks for your help!

+ 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