+ Reply to Thread
Results 1 to 11 of 11

Let user select file to open

  1. #1
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329

    Let user select file to open

    Hello.

    I have a script that imports a csv-file and delimit the inputs with colon.
    Today the code is hard coded and I would like the user to be able to select which file to import.
    How can I do this?

    Current code:
    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: Let user select file to open

    Please Login or Register  to view this content.
    I don't know how this can be applied to your code up top there as this will actually open the csv as its own workbook, which is what you were asking for.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Let user select file to open

    Hi

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329

    Re: Let user select file to open

    Quote Originally Posted by Richard Buttrey View Post
    Hi

    Please Login or Register  to view this content.
    It seems to work well until the ....etc code starts.
    I have written this way:
    Please Login or Register  to view this content.
    What is marked in red text is causing a problem since it is hardcoded filename without the extension.
    Can I extract the filenamn from the stFName in some way?

    /Anders

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Let user select file to open

    Are you saying that name is in some way related to the filename? If so what's a typical filename and what do you want that .Name string to be for that example file name.

  6. #6
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329

    Re: Let user select file to open

    In the original code:
    Please Login or Register  to view this content.
    How can I get the filename into the .data-field?
    It need to be the same filename as the imported filename.

    Anders

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Let user select file to open

    Hi,

    In much the same way as before but with an extra variable

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329

    Re: Let user select file to open

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    In much the same way as before but with an extra variable

    Please Login or Register  to view this content.
    Yes, I believe it should be this simple but my knowledge is very limited.
    I still get an error though. "Application defined or object-defined error"

    Please Login or Register  to view this content.
    Any thoughts?

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Let user select file to open

    Difficult to say without seeing the workbook if this element was working before. Would you upload the workbook?

  10. #10
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329

    Re: Let user select file to open

    There are some differences from the orignial code:
    Please Login or Register  to view this content.
    Your code:
    Please Login or Register  to view this content.
    The parameter stfName = Returns only "data". Not data_267798_7267 so there is something wrong there as well.


    Attachments

    Here is the data file I am trying to import.
    data_267798_7267.csv
    Here is the xlsm file that imports the file. It is unfortunately in swedish. On the second slide There is a macro button that starts the import. (1.Hämta Data)
    Orderhandling.zip

  11. #11
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329

    Re: Let user select file to open

    Any suggestions how to get this to work?

    This code does not give the result I need:
    Please Login or Register  to view this content.
    If the stfPath = C:\Users\ks41750\Google Drive\Skövde HF\Webshop\data_267798_7267.csv

    The stfName returns only data. Not data_267798_7267 which I'd like.
    Last edited by a94andwi; 03-13-2014 at 10:47 AM.

+ 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] Userform that allows user to select an open file?
    By anon in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-01-2014, 05:25 AM
  2. [SOLVED] Macro that prompts user to select a file to open and perform another macro on this file
    By grimmy26 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-16-2014, 08:39 AM
  3. [SOLVED] Open specific folder, select file to open and copy then paste
    By Kranky in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-22-2012, 12:14 AM
  4. Not able to open or select other work books while user form is activate
    By rvc81 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-16-2011, 06:14 AM
  5. Replies: 12
    Last Post: 06-07-2011, 04:17 AM

Tags for this Thread

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