+ Reply to Thread
Results 1 to 2 of 2

Using external text file to assign VBA variables for multiple excel files

  1. #1
    Registered User
    Join Date
    10-15-2012
    Location
    Cary
    MS-Off Ver
    Excel 2003
    Posts
    18

    Using external text file to assign VBA variables for multiple excel files

    Hello Forum,

    I am working on designing a chemical inventory using Excel and VBA. One of the functions within the spreadsheet is to "inquire" about a chemical which emails a respective group's outlook distribution list based on the chemical record's details.

    My problem arises from the inherit limitation of not being able to share a macro enabled document. My work around for this problem was to create multiple chemical inventories (~13, one for each laboratory group) and have each record export a *.csv file to a shared location when a save event is triggered. When determined necessary, a "site-wide" chemical inventory can be "refreshed" which compiles all the various saved *.csv files into their workbook for a "master" view.

    The piece that I see giving some issue is updating the code of ~13 or so excel files when a small change occurs. More specifically, this section in the code is likely to change from time to time:

    If Group = "160N-517" Then TeamName = "Biophysical Characterization and MS-S Inorganics"
    If Group = "175" Then TeamName = "QCCA"
    If Group = "120N" Then TeamName = "Bio"
    If Group = "160N-417" Then TeamName = "Extractable and Leachable"
    If Group = "140" Then TeamName = "Pulmonary and Nasal"
    If Group = "140" Then TeamName = "Metals"
    If Group = "160N-317" Then TeamName = "Stability"
    If Group = "160N-220" Then TeamName = "Stability"
    If Group = "160N-318" Then TeamName = "Stability"
    If Group = "160N-518" Then TeamName = "Stability"
    If Group = "160N-218" Then TeamName = "Product Venture Group"
    If Group = "160S-230" Then TeamName = "Sterile Analytical or Analytical Research and Development"

    If Group = "160N-517" Then Blaster = "G-ST-RTP-Inventory-BPC-MS-S"
    If Group = "175" Then Blaster = "G-ST-RTP-Inventory-QCCA"
    If Group = "120N" Then Blaster = "G-ST-RTP-Inventory-Bio"
    If Group = "160N-417" Then Blaster = "G-ST-RTP-Inventory-EL"
    If Group = "140" Then Blaster = "G-ST-RTP-Inventory-PN"
    If Group = "140" Then Blaster = "G-ST-RTP-Inventory-Metals"
    If Group = "160N-317" Then Blaster = "G-ST-RTP-Inventory-Stability-1"
    If Group = "160N-220" Then Blaster = "G-ST-RTP-Inventory-Stability-1"
    If Group = "160N-318" Then Blaster = "G-ST-RTP-Inventory-Stability-2"
    If Group = "160N-518" Then Blaster = "G-ST-RTP-Inventory-Stability-2"
    If Group = "160N-218" Then Blaster = ""
    If Group = "160S-230" Then Blaster = "G-ST-RTP-Inventory-Analytical"

    What is the best way to handle changing this data? My recent idea is to create a text file or xml file and paste in the variables there. I would then call the *.txt or *.xml (or what is best) to have the code update those variables. Any suggestions?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Using external text file to assign VBA variables for multiple excel files

    I would recommend a LIST sheet, possibly hidden, in your workbook with a 3 column table.

    A: List of Group codes (160N-517, 715, etc...)
    B: Corresponding list of TeamNames (QCCA, Bio, etc...)
    C: Corresponding list of Blaster strings (G-ST-RTP-Inventory-BPC-MS-S, G-ST-RTP-Inventory-QCCA, etc...)

    This list can be linked to query of a stored CSV file or you can simply have a code that reimports that data from a CSV to that sheet before you process.

    From that list, you can do a SEARCH of column A to find the Group, then use an OFFSET() to the right to utilize the corresponding values, whatever they may be.

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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