+ Reply to Thread
Results 1 to 8 of 8

Import CSV based on file selection

  1. #1
    Registered User
    Join Date
    01-26-2011
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    49

    Import CSV based on file selection

    Good Afternoon,

    I need help with a CSV import please. I have a working code that clears existing queries/connections and then imports a specific file from my desktop:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    However I would like to make the file that is being imported a variable. So once the user clicks the button this macro is tied to, i would like an explorer window to open and the user can choose which file to import. How do I do that?

    Appreciate your time and help!

    Cheers

    Maike

  2. #2
    Valued Forum Contributor
    Join Date
    01-14-2013
    Location
    Austria
    MS-Off Ver
    2016 / 2019
    Posts
    339

    Re: Import CSV based on file selection

    you can use this function to get a file name (adopt to your needs)
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    cheers

  3. #3
    Registered User
    Join Date
    01-26-2011
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Import CSV based on file selection

    I appreciate the quick response. I changed the code as you had marked and it lets me select the file. However it does not import the data
    Attachment 673487

    looks like this now:

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    01-14-2013
    Location
    Austria
    MS-Off Ver
    2016 / 2019
    Posts
    339

    Re: Import CSV based on file selection

    I cannot open the attachment

    for debugging use your original code and in the debug window (immediate window) write
    ?" Source = Csv.Document(File.Contents(""C:\Users\maike\OneDrive\Desktop\CHIWA.csv""),[Delimiter="","", "
    copy the result to a text editor (notepad?)
    then run the new code and set a break point on "if sFile"
    in the debug window write
    ?sFile
    should print the complete path including the selected file and then
    ?" Source = Csv.Document(File.Contents(" & sFile & "),[Delimiter="","",
    copy this also to the text editor and compare the result (you should use the same csv-file as in your hard coded version

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Import CSV based on file selection

    Hi Maike,

    I've had this problem before and used Application.FindFile which opens a Dialog and lets the user select the file they need. It answered by problem. Read about it at:
    https://docs.microsoft.com/en-us/off...ation.FindFile
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  6. #6
    Registered User
    Join Date
    01-26-2011
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Import CSV based on file selection

    Apologies.. I am not overly good at VBA and have never debugged before. I am also not good enough at syntax to just read about a command and know how to use it

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Import CSV based on file selection

    OK Maike,

    After looking at all the code above I thought you needed a simpler method. Find the attached and see what it does. It has a one line macro and a single button. See if this helps.

    FindFile Demo Basic.xlsm

  8. #8
    Registered User
    Join Date
    01-26-2011
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Import CSV based on file selection

    I guess I could use that to open the file, copy/paste the values and close it again. That does it! Thank you

+ 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. Import a CSV file based on the value in a cell as the file name
    By chrismeeky in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-04-2018, 01:53 AM
  2. Create an import file based on another file
    By Maureen405 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-20-2014, 10:46 AM
  3. Create an import file based on another spreadsheet
    By Maureen405 in forum Excel General
    Replies: 3
    Last Post: 10-17-2014, 04:27 PM
  4. Replies: 6
    Last Post: 08-30-2013, 01:59 AM
  5. Import CSV file based on Date and Time
    By tdonegan in forum Excel General
    Replies: 1
    Last Post: 05-16-2013, 04:38 AM
  6. File import - select file and import sheet(1) from closed workbook
    By Armitage2k in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2011, 03:15 AM
  7. [SOLVED] import worksheet based on a selection
    By John Casteel in forum Excel General
    Replies: 0
    Last Post: 06-15-2006, 01:55 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