Browse and attach file in a UserForm

  • Thread starter Jeroen Kluytmans
  • Start date
J

Jeroen Kluytmans

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
 
T

Tom Ogilvy

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).Offset(1,0)

End Sub

now bk is object.
 
J

Jeroen Kluytmans

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top