+ Reply to Thread
Results 1 to 7 of 7

How to choose macro from options

  1. #1
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    How to choose macro from options

    I have 4 macros that are tailored to import data depending on the file type.

    1. Imports htm files
    2. Imports Txt files
    3. Imports CSV files
    4. Imports DBF files

    What I would like to do is allow users to select which type of file is being imported so that the correct import macro is automatically run.

    For example:

    User input ---> FileType = InputBox("Enter File Type", "File Type", "htm")

    If filetype = text then
    call Import_Txt

    If filetype = htm then
    Call Import_htm

    If filetype = csv then
    Call Import_csv

    If filetype = dbf then
    Call Import_dbf

    I only need the correct macro to run.

    Any assistance would be appreciated.

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: How to choose macro from options

    this could be the basic start of your program if all the macros are in the same file...

    Please Login or Register  to view this content.
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: How to choose macro from options

    Thanks for the reply Ernest.
    I will give it a whirl.

  4. #4
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: How to choose macro from options

    cool....have fun

  5. #5
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: How to choose macro from options

    Thanks again Ernest. Code works perfectly.

    As an additional question:

    I have created a Userform with Option Buttons in an attempt to do the same thing, but avoid the possibility of user syntax error.

    Control Name Caption
    Userform FileSlct Select File Type
    Option Button TxtOptionButton Text Files
    Option Button HtmOptionButton Html Files
    Option Button CsvOptionButton CSV Files
    Option Button DbfOptionButton DBF Files
    Command Button OKButton OK
    Command Button CancelButton Cancel

    This is my import macro:
    Please Login or Register  to view this content.


    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

    I have never worked with Userforms before, so I am in the dark whether my code is incorrect or incomplete.

    When I try to run the import macro I get a runtime 424 error.

    Any assistance would be appreciated.

    Thanks again.
    Last edited by anrichards22; 06-28-2014 at 02:46 AM.

  6. #6
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: How to choose macro from options

    It hard to tell from here...can you upload a file with confidential data removed....

  7. #7
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: How to choose macro from options

    Rather than use optionbuttons which I don't know how to use at this stage I have opted to use commandbuttons, one for each file type which I have managed to work out how to use.

    Thanks for your assistance Judge, much appreciated.

+ 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. Choose from multiple options then populate another page
    By robsanders in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-12-2012, 10:31 PM
  2. Choose Filter Options based on values in range
    By booo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-21-2011, 08:46 PM
  3. choose 1 options then 1 cell hidden
    By lunar_star in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-18-2007, 07:35 AM
  4. Replies: 1
    Last Post: 07-06-2006, 05:25 PM
  5. [SOLVED] why the date convert to number when i choose formulas from options
    By Musab Saleh in forum Excel General
    Replies: 1
    Last Post: 04-05-2006, 02:45 PM

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