+ Reply to Thread
Results 1 to 5 of 5

Command Button to be used as Browse... for selecting a file to be used...

  1. #1
    Registered User
    Join Date
    05-09-2004
    Posts
    21

    Command Button to be used as Browse... for selecting a file to be used...

    The command button is part of a userform. I need the command button to open a browse files window so that the user can select the file. This file will then be opened, certain data ranges will be selected, and then copied, and then the workbook will be closed, and those copied values will be pasted into the original workbook. How can I do this, I have a pretty good idea about the selecting, copying, pasting part, but I can't figure out how to get the browse files window, and then have the program do those actions on the user selected file. Thanks.

  2. #2
    Registered User
    Join Date
    05-09-2004
    Posts
    21
    Ok, so I'm getting there... I think... slowly... this is what I've got so far... However, I need to make it so that the code for the button stops if you exit the open dialogue instead of selecting a file to open (otherwise it closes the workbook).

    Please Login or Register  to view this content.

  3. #3
    Tom Ogilvy
    Guest

    Re: Command Button to be used as Browse... for selecting a file to be used...

    Dim fName as String
    Dim bk as Workbook

    fName = Application.GetOpenFileName(Excel Files (*.xls),*.xls")

    if fName = "False" then
    ' user hit cancel'
    exit sub
    End if

    set bk = workbooks.Open(fName)

    bk.Worksheets("Data").Range("A1:F20").Copy _
    Destination:=ThisWorkbook.worksheets("Master") _
    .Cells(rows.count,1).End(xlup).Offset(1,0)
    bk.Close SaveChanges:=False

    --
    Regards,
    Tom Ogilvy

    "RPIJG" <[email protected]> wrote in
    message news:[email protected]...
    >
    > The command button is part of a userform. I need the command button to
    > open a browse files window so that the user can select the file. This
    > file will then be opened, certain data ranges will be selected, and
    > then copied, and then the workbook will be closed, and those copied
    > values will be pasted into the original workbook. How can I do this, I
    > have a pretty good idea about the selecting, copying, pasting part, but
    > I can't figure out how to get the browse files window, and then have
    > the program do those actions on the user selected file. Thanks.
    >
    >
    > --
    > RPIJG
    > ------------------------------------------------------------------------
    > RPIJG's Profile:

    http://www.excelforum.com/member.php...fo&userid=9285
    > View this thread: http://www.excelforum.com/showthread...hreadid=480140
    >




  4. #4
    Registered User
    Join Date
    05-09-2004
    Posts
    21
    Fantastic thanks Tom

  5. #5
    Tom Ogilvy
    Guest

    Re: Command Button to be used as Browse... for selecting a file to be used...

    You have received an answer that does what you asked.

    --
    Regards,
    Tom Ogilvy

    "RPIJG" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Ok, so I'm getting there... I think... slowly... this is what I've got
    > so far... However, I need to make it so that the code for the button
    > stops if you exit the open dialogue instead of selecting a file to open
    > (otherwise it closes the workbook).
    >
    >
    > Code:
    > --------------------
    >
    > Private Sub CommandButton1_Click()
    > 'Open Dialogue
    > Application.FindFile
    > 'Select Data from Opened File
    > ActiveWorkbook.Sheets("Sheet1").Range("A14:L21").Select
    > 'Copy Data from Opened File
    > Selection.Copy
    > 'Close Opened File
    > ActiveWorkbook.Close
    > 'Paste Data into Template File
    > ActiveWorkbook.Sheets("Sheet1").Range("A28:L35").Select
    > ActiveSheet.Paste
    > End Sub
    >
    > --------------------
    >
    >
    > --
    > RPIJG
    > ------------------------------------------------------------------------
    > RPIJG's Profile:

    http://www.excelforum.com/member.php...fo&userid=9285
    > View this thread: http://www.excelforum.com/showthread...hreadid=480140
    >




+ 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