+ Reply to Thread
Results 1 to 18 of 18

How do i code a VBA to ask the user to select which file to use

  1. #1
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    How do i code a VBA to ask the user to select which file to use

    The current VBA i have is as follows;

    Please Login or Register  to view this content.
    I want to be able to code it so the macro asks the user which file to use but will use the same steps following this?

    Any ideas

  2. #2
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: How do i code a VBA to ask the user to select which file to use

    I have tried this but there is an error somewhere as it pastes all the data from a summary sheet to the next sheet in the workbook.

    I need it to open a new file, copy all the data and paste it to "test sheet" then close the opened sheet.

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How do i code a VBA to ask the user to select which file to use

    It will be good if you try explaining your problem with the help of an attached excel file. Can you clearly state what you require the macro to do?

    Also, you can do away with the select & activate statements.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: How do i code a VBA to ask the user to select which file to use

    I required coding to prompt the user for the file, copy all the data from the data sheet of the opened file and paste it into the data tab of the summary template.

    Attached is the summary document.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: How do i code a VBA to ask the user to select which file to use

    Can you view the attachment

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How do i code a VBA to ask the user to select which file to use

    I just edited the code you had to this
    Please Login or Register  to view this content.
    Add the pivot refresh code after this.

  7. #7
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: How do i code a VBA to ask the user to select which file to use

    Thanks, i get the following error message with this line;

    Please Login or Register  to view this content.
    Error is Method 'Range' of object _global failed

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

    Re: How do i code a VBA to ask the user to select which file to use

    Try this line of code:

    Please Login or Register  to view this content.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  9. #9
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: How do i code a VBA to ask the user to select which file to use

    Still not happy.

    Please Login or Register  to view this content.
    Once the file has been opened it needs to copy the workbook and then switch back to the previous workbook and paste the copied data into the sheet.

    I'm not sure this is doing those things.

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How do i code a VBA to ask the user to select which file to use

    Ok hold on. I have already provided you the code to do the copy paste. What is currently not working is the workbooks.open part. Can you give me the path from where you open the file ? Also, give me the name of the file.

  11. #11
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: How do i code a VBA to ask the user to select which file to use

    The filepath of the data is;

    \\Via.novonet\dfs\LIFE\F\INVReporting\CONFIDENTIAL\Inv_Reporting_2012\Source Files\S29

    File name will be S29 Data then DDMMYY (this will be a different date each month, which is why i wanted to prompt the user to select which file

  12. #12
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How do i code a VBA to ask the user to select which file to use

    There is no drive letter before the path? Like C or D?

  13. #13
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: How do i code a VBA to ask the user to select which file to use

    It's a network drive so doesn't need to be?

  14. #14
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How do i code a VBA to ask the user to select which file to use

    Try this
    Please Login or Register  to view this content.
    Last edited by arlu1201; 05-15-2012 at 10:04 AM. Reason: Edited code

  15. #15
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: How do i code a VBA to ask the user to select which file to use

    I have updated and re run

    Please Login or Register  to view this content.
    Error message is object required.

  16. #16
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How do i code a VBA to ask the user to select which file to use

    Sorry, i have made the changes to the above code.

  17. #17
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: How do i code a VBA to ask the user to select which file to use

    Spot on, works a treat, thank you for help, really apprecaite it!

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

    Re: How do i code a VBA to ask the user to select which file to use

    Hi,

    Did you ever try "Application.FindFile"??

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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