+ Reply to Thread
Results 1 to 11 of 11

Create drop down menu to select file extension

  1. #1
    Forum Contributor
    Join Date
    03-14-2015
    Location
    Mexico
    MS-Off Ver
    365
    Posts
    279

    Create drop down menu to select file extension

    I have a challenge with this code that i found. I just copied part of the code because here is what i want to replace.

    How can I provide the users with a drop down menu for them to select xlsx, pdf, xml, etc instead of manually replacing the word "pdf" here:
    "If InStr(1, a(i), "pdf") > 0 Then 'in case you want excel, change to xlsx or xlsm"



    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Create drop down menu to select file extension

    Perhaps something like this
    - VBA calls a userform which contains a dropdown combobox
    - selected value in combobox passed to variable "Extension"
    - "Extension" is a declared as a public variable so that the value is known to all modulesand procedures
    - as message box demonstrates VBA can use value of "Extension"

    To test in attached file run with {CTRL}k

    (there are other ways to achieve the same thing)

    In standard module
    Please Login or Register  to view this content.
    Simple userform module
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Contributor
    Join Date
    03-14-2015
    Location
    Mexico
    MS-Off Ver
    365
    Posts
    279

    Re: Create drop down menu to select file extension

    Hi, I am trying to execute this however while running the macro I got this message "Variable not defined" for this line "Extension = ComboBox1.Value" within the Userform.

    Can you please help?

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Create drop down menu to select file extension

    Are you running it in the workbook I attached?
    I downloaded the workbook from the forum, opened it, and ran the macro with {CTRL}k - it ran without any problem. So it should run for you.
    Extension is declared as a public variable in a standard module - so I do not understand why you are getting that message.

    As a temporary workaround you could instead save the value to the worksheet.

    (In userform module) Replace
    Please Login or Register  to view this content.
    With
    Please Login or Register  to view this content.
    (In the Message Box line) Replace
    Please Login or Register  to view this content.
    With
    Please Login or Register  to view this content.
    I will post an alternative method tomorrow - but I am totally baffled by the problem
    Last edited by kev_; 04-12-2018 at 05:48 PM.

  5. #5
    Forum Contributor
    Join Date
    03-14-2015
    Location
    Mexico
    MS-Off Ver
    365
    Posts
    279

    Re: Create drop down menu to select file extension

    Hi, I think it would be easier to share my file. I put some notes in the sheet1.

    Thanks,
    Attached Files Attached Files

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Create drop down menu to select file extension

    Give this a try.
    Attached Files Attached Files
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  7. #7
    Forum Contributor
    Join Date
    03-14-2015
    Location
    Mexico
    MS-Off Ver
    365
    Posts
    279

    Re: Create drop down menu to select file extension

    Thanks for the code Bakerman2. I tested it, works fine. I would like to know if it is possible to select two kind of file types.

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Create drop down menu to select file extension

    Will have to look into that later but was working on this.
    Changed the code in the userform to this so only extensions present in SourceFolder are listed in Combobox.

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

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Create drop down menu to select file extension

    Changed the Combobox to a multiselect ListBox.
    Select extension(s) and click commandbutton.
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    03-14-2015
    Location
    Mexico
    MS-Off Ver
    365
    Posts
    279

    Re: Create drop down menu to select file extension

    Terrific!, that worked perfectly for what i needed. Thanks

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Create drop down menu to select file extension

    Glad to help and thanks for rep+.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    Last edited by bakerman2; 04-13-2018 at 06:53 PM.

+ 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. [SOLVED] Select from a drop down menu text and return a percentage
    By SusanWi in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 12-18-2017, 12:54 PM
  2. [SOLVED] Creating a drop down menu to select a sheet
    By digitised in forum Excel General
    Replies: 10
    Last Post: 01-25-2017, 10:03 AM
  3. Select from a drop down menu using VBA
    By Johnnyv015 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2014, 02:55 PM
  4. [SOLVED] I cant work out how to create a drop down menu that relates to another drop down menu
    By louise2613 in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 08-18-2012, 01:49 PM
  5. drop down menu to select and hide certain rows and columns
    By ROM in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-11-2010, 09:39 AM
  6. select multiple items from drop-down menu
    By jcavigli in forum Excel General
    Replies: 2
    Last Post: 05-25-2008, 11:50 AM
  7. [SOLVED] Drop down menu-Can I create a drop down menu
    By murph in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-21-2006, 10:25 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