Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Browse Button Fraggs[_20_] Excel Programming 1 June 14th 05 02:45 PM
Saving a file from a command button with user input Owen[_6_] Excel Programming 2 July 6th 04 10:02 PM
Disable Command Button when File name begins with Customer? RPIJG[_58_] Excel Programming 1 June 24th 04 05:53 PM
selecting workbook/worksheet from browse button monika Excel Programming 9 February 8th 04 09:40 AM
Browse Button for File Save Todd Huttenstine[_2_] Excel Programming 4 December 22nd 03 03:28 AM


All times are GMT +1. The time now is 03:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"