Need help modifying this code to let command button run it (browse to file, save that file, post link in cell)

Erick87

New Member
Joined
Mar 28, 2016
Messages
1
Greetings,

This is my first post here and i am quite new to VBA I have been looking around this forum for a while and so far it helped me alot.

I have a question: I need a command button in a userform to execute a file browse window where the user can search for a file (word or pdf) save that file to a network location and put the link in a cell in the excel worksheet.

I have been looking around and found this solution by another user.

Code:
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)         ' Retreive cell column number
    cell_check = ActiveCell.Column
    If cell_check = 21 Then 'checks if Column 21 (U) is selected
                    Dim file_pick As Long
             ' Open the file dialog
            With Application.FileDialog(msoFileDialogOpen)
                .AllowMultiSelect = False
                .Show
             ' Display paths of each file selected
            For file_pick = 1 To .SelectedItems.Count
                file_address = .SelectedItems(file_pick)
            Next file_pick
             End With
        ' Created hyperlink and adds HERE text
    ActiveCell.Hyperlinks.Add Anchor:=Selection, Address:=file_address, TextToDisplay:="HERE"
        'Disables Right Click menu
    Cancel = True
    
    End If

End Sub

This solution looks great, however i would like to modify it so that the file browse and save action happens when the use selects a 'upload' command button.
instead of rightclicking a cell.

I Hope you gys can help me with this question!

The post where the code above is from is this
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,215,461
Messages
6,124,953
Members
449,198
Latest member
MhammadishaqKhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top