+ Reply to Thread
Results 1 to 12 of 12

VBA to get data from a user selected file

  1. #1
    Registered User
    Join Date
    08-07-2016
    Location
    USA
    MS-Off Ver
    2016
    Posts
    19

    VBA to get data from a user selected file

    First time post, I am trying to write a program to allow a user to open an excel workbook into the current workbook.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: VBA to get data from a user selected file

    open an excel workbook into the current workbook
    Please clarify what you mean by this. It is a confusing statement as this is not an event that happens in Excel. You can have more than one workbook open, or you can copy one workbook into another. I'm not sure what you want.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: VBA to get data from a user selected file

    You can try this code :

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-07-2016
    Location
    USA
    MS-Off Ver
    2016
    Posts
    19

    Re: VBA to get data from a user selected file

    I would like to be able to grab data from an existing excel workbook. So if I open the workbook with the vba code, there is a button that will allow the user to select which file is to be opened

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: VBA to get data from a user selected file

    This may be what you are looking for: http://analysistabs.com/vba/open-fil...-example-code/

  6. #6
    Registered User
    Join Date
    08-07-2016
    Location
    USA
    MS-Off Ver
    2016
    Posts
    19

    Re: VBA to get data from a user selected file

    this works in opening the file, but i would like the file to be opened into the workbook the macro is in.

  7. #7
    Registered User
    Join Date
    08-07-2016
    Location
    USA
    MS-Off Ver
    2016
    Posts
    19

    Re: VBA to get data from a user selected file

    Quote Originally Posted by sanram View Post
    You can try this code :

    Please Login or Register  to view this content.
    this great sanram, is there a way to get the file i choose to open into sheet 2 of the current workbook?

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: VBA to get data from a user selected file

    I don't believe what you are asking is possible. You would have to copy the excel document you have on file and paste it into the new document.

    Can you explain the business rationale of what you are wishing to happen. Perhaps if we understand the business scenario, we can offer a valid solution.

  9. #9
    Registered User
    Join Date
    08-07-2016
    Location
    USA
    MS-Off Ver
    2016
    Posts
    19

    Re: VBA to get data from a user selected file

    alansidman:

    the rationale being there is an exported excel file(and future files) that needs to be reformatted. Below is the working code. it is able to insert a selected excel file into sheet 2, then transfer that data into sheet 1 were it will be properly reformatted

    Please Login or Register  to view this content.
    Last edited by alansidman; 08-09-2016 at 09:01 PM.

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: VBA to get data from a user selected file

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)

    BTW: Your code does what I indicated had to happen. It opens a file, copies the sheet and pastes it into the new file. It does this with a loop that looks at each sheet and copies them into the new workbook.
    Last edited by alansidman; 08-09-2016 at 09:04 PM.

  11. #11
    Registered User
    Join Date
    08-07-2016
    Location
    USA
    MS-Off Ver
    2016
    Posts
    19

    Re: VBA to get data from a user selected file

    thanks for the information Alansidman, the next step i wish to accomplish is to add functions to the newly copied sheet. for instance i wish to take the value of cell E2 multiply it by two and the multiply it be the first value in D2 (function looks like =2*E2*MID(D2,1,1). The issue I'm facing is that the function doesnt seem to work down the column it is in. it will return the same value, even if the values in D2 differ down the column

  12. #12
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: VBA to get data from a user selected file

    Since this is a new issue, I suggest that you mark this thread solved and open a new thread with your requirements. It will generate more responses than a long open unresolved thread.

+ 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] Macro to prompt user to select a file and the selected file should saved in location
    By logesh excel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-26-2015, 03:43 PM
  2. [SOLVED] Unable to programatically open a user selected file.
    By LittleB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-16-2014, 01:13 PM
  3. [SOLVED] Get external data from a user selected .txt file
    By trisoldee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2014, 03:00 PM
  4. Trying to get value in user selected file
    By sehamm10 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-23-2013, 10:24 PM
  5. [SOLVED] Import user selected columns from a text file
    By aarho in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-11-2012, 08:28 PM
  6. How to extract file name from user selected file via Application.FileDialog
    By Jpdatabase in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-09-2012, 04:45 AM
  7. import data from .txt file selected by user
    By ahartman in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-29-2008, 03:34 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