+ Reply to Thread
Results 1 to 12 of 12

Browse button

Hybrid View

  1. #1
    Registered User
    Join Date
    09-12-2012
    Location
    Sewell, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    7

    Browse button

    I started working with excel about 2 months ago. My supervisor requested that I create a button ("Browse") that pulls a saved file (an xls. file pulled from a database, then saved to my computer), then takes that file and pastes the information into a different tab.

    Can someone help me out here? I've been looking things up on forums all day trying to figure this stuff out but due to having very limited experience, I don't understand alot of the lingo involved ect.

  2. #2
    Valued Forum Contributor
    Join Date
    05-08-2012
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2003, 2010
    Posts
    811

    Re: Browse button

    You are looking for a "macro".

    A macro can do that
    Click on star (*) below if this helps

  3. #3
    Registered User
    Join Date
    09-12-2012
    Location
    Sewell, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Browse button

    Haha. I know that much. I'm saying, how should I go about creating the macro? Can I just record it somehow? Or, does someone have a macro code I could look at to base mine off of? I assume this is incredibly simple for someone who knows what they're doing...

  4. #4
    Valued Forum Contributor
    Join Date
    05-08-2012
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2003, 2010
    Posts
    811

    Re: Browse button

    Perhaps you might upload sample data

  5. #5
    Registered User
    Join Date
    09-12-2012
    Location
    Sewell, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Browse button

    bump bump bump Please help!!

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: Browse button

    if the file name is always the same, and it is always in the same location, you could try and use the learn/record macro function, then create a macro button to activate it
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  7. #7
    Registered User
    Join Date
    09-12-2012
    Location
    Sewell, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Browse button

    The file is not always the same. I want to click a button and have it open my file folder, then I want to be able to browse for the specific file I need, open it and have the information paste into a specific tab. Can someone please give me a macro that can do this?

  8. #8
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Browse button

    Sample code:
    Sub tgr()
        
        'Declare variables
        Dim wsDest As Worksheet     'This is the sheet that data will be written to
        Dim strFilePath As String   'This is a string variable that will contain the full path to the chosen file
        
        'Use Application.GetOpenFilename to allow user to choose a specific file
        strFilePath = Application.GetOpenFilename("Excel Files, *.xls*")
        If strFilePath = "False" Then Exit Sub  'User pressed cancel, exit macro
        
        'Assign wsDest to the appropriate sheet
        Set wsDest = ActiveWorkbook.ActiveSheet
        
        'Turn off screenupdating so user doesn't see the chosen workbook being opened and operations performed
        'This avoids "screen flickering" because executed actions happen very rapidly
        'Turning this off also speeds up code run-time because it doesn't have to display what's happening on the screen
        Application.ScreenUpdating = False
        
        With Workbooks.Open(strFilePath)
            'Do stuff with the workbook here
            'For example, this will copy sheet1 cell A1 to the next available row in column A of wsDest:
            .Sheets(1).Range("A1").Copy wsDest.Cells(Rows.Count, "A").End(xlUp).Offset(1)
            
            'Close the workbook, don't save changes
            .Close False
        End With
        
        'Turn screenupdating back on
        Application.ScreenUpdating = True
        
        'Object variable cleanup
        Set wsDest = Nothing
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  9. #9
    Registered User
    Join Date
    09-12-2012
    Location
    Sewell, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Browse button

    Thanks for help tiger--It gets to this line

    .Sheets(1).Range("A1").Copy wsDest.Cells(Rows.Count, "A").End(xlUp).Offset(1)

    Then a "debugger" pops up. I'm not sure what the criteria is--I just want the page to copy and paste the entire the into "Sheet2". Is that possible?

  10. #10
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Browse button

    What is the exact error you're getting? That code is simple enough that is shouldn't cause an error.

    If you just want to copy all of the contents of the chosen workbook sheet1, then use (replace ... with desired destination location):
    .Sheets(1).UsedRange.Copy Destination:=...

  11. #11
    Registered User
    Join Date
    09-12-2012
    Location
    Sewell, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Browse button

    the desired location is "sheet2" on the page I'm on when I actually run the macro

  12. #12
    Registered User
    Join Date
    09-12-2012
    Location
    Sewell, New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Browse button

    you're saying replace the line I posted with the one you just did?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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