ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Browse and attach file in a UserForm (https://www.excelbanter.com/excel-programming/324642-browse-attach-file-userform.html)

Jeroen Kluytmans

Browse and attach file in a UserForm
 
Hello,

I would like to make an option in a userform to browse a file and add
it to the excel sheet. I don't have a clue how to make this. Can
anybody help me with a start?

So far I can open a file, but I can not manage to just make a linkt to
the object, or load the file as object in the excel file. It would be
best if the link to the file or the object can be copied in a cell in
the worksheet.

Private Sub CommandButton2_Click()

Dim TheFile As Variant
TheFile = Application.GetOpenFilename("Excel files (*.xls), *.xls", ,
_
"Pick a file")
If TheFile < False Then
Workbooks.Open TheFile
End If
End Sub

Any help welcome
Kind regards,
Jeroen Kluytmans

Tom Ogilvy

Browse and attach file in a UserForm
 
Generally, you don't embed on excel file inside another. Generally, you
open both files and copy the information you need from one to the other.
You could link them with a formula. And easy way is to copy the data and
then do a past special and select the link option. this puts in a linking
formula and can be done with code.


Private Sub CommandButton2_Click()

Dim TheFile As Variant
Dim bk as workbook

TheFile = Application.GetOpenFilename( _
"Excel files (*.xls), *.xls", , _
"Pick a file")

If TheFile < False Then
set bk =Workbooks.Open( TheFile)
Else
exit sub
End If


bk.worksheets(1).Cells(1,1).currentRegion.copy _
Destination:=me.cells(rows.count,1).end(xlup).Offs et(1,0)

End Sub

now bk is object.


--
Regards,
Tom Ogilvy




--
Regards,
Tom Ogilvy

"Jeroen Kluytmans" wrote in message
om...
Hello,

I would like to make an option in a userform to browse a file and add
it to the excel sheet. I don't have a clue how to make this. Can
anybody help me with a start?

So far I can open a file, but I can not manage to just make a linkt to
the object, or load the file as object in the excel file. It would be
best if the link to the file or the object can be copied in a cell in
the worksheet.

Private Sub CommandButton2_Click()

Dim TheFile As Variant
TheFile = Application.GetOpenFilename("Excel files (*.xls), *.xls", ,
_
"Pick a file")
If TheFile < False Then
Workbooks.Open TheFile
End If
End Sub

Any help welcome
Kind regards,
Jeroen Kluytmans




Jeroen Kluytmans

Browse and attach file in a UserForm
 
Tom,

Sorry, but I did not specifically mean a xls file. The format of the
file micht be any format. The example was for the xls file, but I
would like to link to any object. I recorded a Macro when linking the
object to the sheet, but this did not give me a clue how to program
this. It would be best if I can really upload a document in the excel
file so that if the file is opened at another computer the file is
embedded in the worksheet. Is this possible?

Regards,
Jeroen Kluytmans

Generally, you don't embed on excel file inside another. Generally, you
open both files and copy the information you need from one to the other.
You could link them with a formula. And easy way is to copy the data and
then do a past special and select the link option. this puts in a linking
formula and can be done with code.


Private Sub CommandButton2_Click()

Dim TheFile As Variant
Dim bk as workbook

TheFile = Application.GetOpenFilename( _
"Excel files (*.xls), *.xls", , _
"Pick a file")

If TheFile < False Then
set bk =Workbooks.Open( TheFile)
Else
exit sub
End If


bk.worksheets(1).Cells(1,1).currentRegion.copy _
Destination:=me.cells(rows.count,1).end(xlup).Offs et(1,0)

End Sub

now bk is object.



All times are GMT +1. The time now is 03:28 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com