Strange Crash in Excel 2010 using Dialog Box and VBA to place hyperlink in cell

BigShango

Board Regular
Joined
May 8, 2014
Messages
106
Can anyone help me? I'm using this code in a dialog box to allow a user to select a file, a hyperlink to that file is then stored in a cell.

Code:
Private Sub CommandButton1_Click()


'file select dialog


Set mb = Workbooks(ActiveWorkbook.Name)


Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
Application.FileDialog(msoFileDialogOpen).Title = "Select nomination form"
Application.FileDialog(msoFileDialogOpen).InitialFileName = mb.Path & "\Nominations Received\"
Application.FileDialog(msoFileDialogOpen).Filters.Clear
intChoice = Application.FileDialog(msoFileDialogOpen).Show


' if file selected, run code. else close dialog
If intChoice <> 0 Then
    'store selected file in textbox
    TextBox1.Value = Application.FileDialog(msoFileDialogOpen).SelectedItems(1)
End If


End Sub


Private Sub CommandButton2_Click()
Set s = Workbooks(ActiveWorkbook.Name).Sheets(ActiveSheet.Name)
r = ActiveCell.Row
C = ActiveCell.Column


s.Cells(r, C).Hyperlinks.Add Anchor:=Selection, Address:=TextBox1.Value, TextToDisplay:="Link"
        
Unload Me
End Sub

This works without a hitch in Excel 2007. On another machine running 2010 it crashes the entire program once you click OK.

It runs from double clicking the cell where the link is to be placed.

Is there something obvious I'm overlooking, or some daft quirk with 2010 where this code would be expected to crash? This is something that I need to roll out across a number of users who will be using various versions of Excel, I'm absolutely snookered if it won't work on 2010.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I've changed the line

Code:
[COLOR=#333333]s.Cells(r, C).Hyperlinks.Add Anchor:=Selection, Address:=TextBox1.Value, TextToDisplay:="Link"
[/COLOR]

to

Code:
s.Hyperlinks.Add Anchor:=s.Cells(r, c), Address:=TextBox1.Value, TextToDisplay:="Link"

And now it works. I have no idea why that makes the difference, but I thought I'd best say so in case anyone else gets the same issue.
 
Upvote 0
I'm having another stupid problem with working between 2007 and 2010.

If this workbook has been saved on the 2010 machine no code works on the 2007 one. I need to go into references and uncheck the Microsoft Outlook 14 library and check the Microsoft Outlook 12 library. It seems like Office 2010 is automatically replacing Outlook 12 with Outlook 14, then Outlook 14 is missing when I go back to 2007. How do I get round this???
 
Upvote 0

Forum statistics

Threads
1,215,007
Messages
6,122,670
Members
449,091
Latest member
peppernaut

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