PDA

View Full Version : [SOLVED] Insert button for upload documents



Fan
08-17-2011, 12:00 AM
I want to create a report template by using excel for people who are in poor countries and don't know much about the computer etc.

So, I want make my worksheet simpler and easy for them to use. And it need to be work in the 'compatibility mode', the old excel version.

Basically, I want to create a button "upload file". It will enable them to attach a photo or word documents to the excel spreadsheet. I know how to do it by click the buttons. Under 'insert object', choose 'Create from File'. Tick the 'Display as Icon'. Then click "Browse'. By selecting the right documents, it's done. They only need to send back the excel document rather than the excel document and other attachments such as .jpgs and .docs.

Now, by saving those people few steps, I want create this "upload file" button. When user click on the button, the "Browse" window will jump up directly.

I don't know how to use write VBA code/Macro to achieve this. Please help!!

Thank you so much in advance.

ads_3131
08-18-2011, 02:39 AM
The below VB will do it...... a click will open a find file dialogue then you can embed a file into a spreadsheet.

See attached Spreadsheet as example .....
______________________________________________________

Private Sub btnAddFile_Click()
Dim vFile As Variant
vFile = Application.GetOpenFilename("All Files,*.*", Title:="Find file to insert")
If LCase(vFile) = "false" Then
Exit Sub
ActiveSheet.OLEObjects.Add Filename:=vFile, Link:=False, DisplayAsIcon:=True, IconLabel:=vFile
End Sub

Fan
08-18-2011, 04:15 PM
Thank you ads_3131. That works! Great! I really appreciated.

:thumb

The below VB will do it...... a click will open a find file dialogue then you can embed a file into a spreadsheet.

See attached Spreadsheet as example .....
______________________________________________________

Private Sub btnAddFile_Click()
Dim vFile As Variant
vFile = Application.GetOpenFilename("All Files,*.*", Title:="Find file to insert")
If LCase(vFile) = "false" Then
Exit Sub
ActiveSheet.OLEObjects.Add Filename:=vFile, Link:=False, DisplayAsIcon:=True, IconLabel:=vFile
End Sub