+ Reply to Thread
Results 1 to 15 of 15

Want to open selected file from listbox (Userform)

  1. #1
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Want to open selected file from listbox (Userform)

    HI,
    I want to update below code to openable file from listbox,

    i want to open selected file using commandbutton1

    For userform code
    Please Login or Register  to view this content.
    in module

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Use Code-Tags for showing your code :
    Please mark your question Solved if there has been offered a solution that works fine for you
    If You like solutions provided by anyone, feel free to add reputation using STAR *

  2. #2
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Want to open selected file from listbox (Userform)

    Above code populating a listbox with files from director

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Want to open selected file from listbox (Userform)

    To open, give the button this code:

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Want to open selected file from listbox (Userform)

    @ Arkadi,

    O.K. I have not looked at the sample Workbook provided yet, 'cause I'm lazy, and it your job in any case!

    Please clean clean your glasses, shake your head so the your ears can give you a wake-up beating, and look at you Code again!

    It will only open the Workbook named Jan 2 Dec 2014\1.12.16, ignoring any other selection from the ListBox.

    Am I correct, or am I correct?

    How about:

    Please Login or Register  to view this content.
    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Want to open selected file from listbox (Userform)

    Hmmm Winon,

    I'm confused this time...
    His findfiles function searches files in the folder "Z:\42766\Jan 2 Dec 2014\1.12.16\" does it not? The listbox has the filename but not the path...which is the full string...
    Why would my code ignore the listbox part in the open command?
    It is not that I am trying to say I'm right, I just fail to see the flaw in my post? Explain it to me like I'm an idiot (maybe I am, lol)

    When I create the exact same folder structure on my C drive and change the code to C: it works here

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Want to open selected file from listbox (Userform)

    Hi Arkadi,

    O.K. I have not looked at the sample Workbook provided yet, 'cause I'm lazy, and it your job in any case!
    Defeat (but not the hands) admitted! I turn out to be the idiot here, for not checking the sample Workbook first.

    I would appreciate it if you would stop getting "upset" with me, when I ruffle your feathers, though!LOL

    Take care my Friend.

  7. #7
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Want to open selected file from listbox (Userform)

    Thanx all of you , dear Guru ji and Expert ji

    This is my path
    Please Login or Register  to view this content.
    in above path i have more then one folder, now i have 3 folders in above path
    first folder
    Please Login or Register  to view this content.
    second folder
    Please Login or Register  to view this content.
    third folder
    Please Login or Register  to view this content.
    and all file from above folder are populatting in my listbox

    now
    i am trying to open files using command button
    as you provided code to open the files @Arakdi

    Workbooks.Open ("Z:\42766\Jan 2 Dec 2014\1.12.16\" & ListBox1.Value) = this opening only files from the first folder as i mentioned folders above

    if i change the path
    Workbooks.Open ("Z:\42766\Jan 2 Dec 2014\1.12.16\1.12.16\" & ListBox1.Value) = this is opening only second folders file

    if i change again the path
    Workbooks.Open ("Z:\42766\Jan 2 Dec 2014\1.12.16\1.1.17\" & ListBox1.Value) = this one is opening only the third folders file

    and Guru ji
    Workbooks.Open ("Z:\42766\" & ListBox1.Value) this path have no files
    because above code will open only folders files as we give the path not opening from folders and subfolders


    so need another solution please

    btw
    thanx again for the reply

  8. #8
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Want to open selected file from listbox (Userform)

    Hello Sid,

    Have you seen my Post in your other Thread?: http://www.excelforum.com/showthread.php?t=1172305

    Would that approach not suit you better?

    Regards.
    Attached Files Attached Files
    Last edited by Winon; 02-04-2017 at 02:55 AM. Reason: Atttached sample file for clarification.

  9. #9
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Want to open selected file from listbox (Userform)

    Dear, sir Winon

    i want to populate listbox with my files,
    while you sample file (Hyperlink Directory Contents.xls‎) is awesome. but here is the condition is different so i have to user listbox to populate the list of files so i can't use this file in above condition

    please do something about above code

    and
    thanx again

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,356

    Re: Want to open selected file from listbox (Userform)

    Here you go.
    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.

  11. #11
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Want to open selected file from listbox (Userform)

    Hello, bakerman2

    working perfectly

    thanx a lot all of you

    thread closed

  12. #12
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,356

    Re: Want to open selected file from listbox (Userform)

    You're welcome and thanks for adding rep points.

  13. #13
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Want to open selected file from listbox (Userform)

    @Winon I hope I did not seem upset and you were just joking my friend... I took no offense at all

  14. #14
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Want to open selected file from listbox (Userform)

    @ Arkadi,

    Not at all my friend. It is just my bad habit of jerking chains!

    All is good!

    Take care,

    Kind Regards.

  15. #15
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Want to open selected file from listbox (Userform)

    Hello Sid,

    bakerman2 was faster than me, but here is my proposed solution as well.

    Thank you for the Rep points, I really appreciate it!
    Attached Files Attached Files

+ 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. Userform Listbox that populates the userform when selected
    By retroboy17 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-12-2015, 07:56 PM
  2. [SOLVED] Add Selected Items From One ListBox to Another ListBox on UserForm
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-27-2014, 06:53 PM
  3. select a item in userform listbox to open a file
    By simeonmein in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-17-2013, 09:36 AM
  4. Put a selected row into a listbox in a userform
    By sebastienkanj in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-09-2013, 08:23 AM
  5. VBA - Populate Listbox based on value selected in another ListBox (On Userform)
    By raaboo in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-12-2012, 11:18 AM
  6. Populate userform listbox based on value selected in another listbox
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-07-2012, 05:16 PM
  7. Display a UserForm based on Data selected in another UserForm's ListBox
    By RPhilbin83 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-26-2011, 11:35 AM

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