Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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. -- RPIJG ------------------------------------------------------------------------ RPIJG's Profile: http://www.excelforum.com/member.php...fo&userid=9285 View this thread: http://www.excelforum.com/showthread...hreadid=480140 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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" wrote in message ... 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Command Button to be used as Browse... for selecting a file to be used...
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").S elect 'Copy Data from Opened File Selection.Copy 'Close Opened File ActiveWorkbook.Close 'Paste Data into Template File ActiveWorkbook.Sheets("Sheet1").Range("A28:L35").S elect 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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Command Button to be used as Browse... for selecting a file to be used...
Fantastic thanks Tom -- RPIJG ------------------------------------------------------------------------ RPIJG's Profile: http://www.excelforum.com/member.php...fo&userid=9285 View this thread: http://www.excelforum.com/showthread...hreadid=480140 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
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" wrote in message ... 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").S elect 'Copy Data from Opened File Selection.Copy 'Close Opened File ActiveWorkbook.Close 'Paste Data into Template File ActiveWorkbook.Sheets("Sheet1").Range("A28:L35").S elect 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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Browse Button | Excel Programming | |||
Saving a file from a command button with user input | Excel Programming | |||
Disable Command Button when File name begins with Customer? | Excel Programming | |||
selecting workbook/worksheet from browse button | Excel Programming | |||
Browse Button for File Save | Excel Programming |