Clicking different cells to open files

danielpalfrey

New Member
Joined
Nov 21, 2018
Messages
17
Hi guys. I have a spread sheet with multiple options on there. Previously I had used hyperlinks to link to word documents for the shipping labels but people are clicking by mistake a making a right hash of things so I am now looking at adding VBA code where you would double click a set cell and the appropriate word file will open. I have set up double click events before but never for this purpose.

Any input would be great.

Regards

Dan
 
Last edited by a moderator:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Whilst it is easy to write code for the double-click event to follow the hyperlink - it does not negate the fact that the user has clicked the hyperlink (and that click would need to be cancelled). Now it seems that there is no Cancel option for FollowHyperlink event. Therefore I suggest this approach:

Adapted from here: https://www.ozgrid.com/forum/forum/...isable-hyperlink-from-opening-until-confirmed

Rather than have the hyperlink address point to the file, have the link point back to the parent cell (i.e. itself). Then you can use the ScreenTip to hold the actual destination address. The following code will follow the address in the ScreenTip. This code belongs in the relevant sheet module.
Code:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    Dim strAddress          As String
    
    Application.EnableEvents = False
    
    strAddress = Target.Address


    If CBool(Len(strAddress)) Then
        If MsgBox(Prompt:="Follow hyperlink?", Buttons:=vbYesNo + vbQuestion, Title:="Hyperlink Activated") = vbYes Then
            Call ThisWorkbook.FollowHyperlink(Address:=strAddress)
        End If
    End If
    
    Application.EnableEvents = True
End Sub
 
Last edited:
Upvote 0
I had originally thought of using something like this

Sub Open_Word_Document() 'Open an existing Word Document from Excel Dim objWord As Object Set objWord = CreateObject("Word.Application") objWord.Visible = True 'Change the directory path and file name to the location 'of the document you want to open from Excel objWord.Documents.Open "C:\Documents\myfile.doc" End Sub

But this seems to target the whole spread sheet rather than a specific cell. If this can be made to target a specific cell then I can get this to work
 
Upvote 0
Whilst it is easy to write code for the double-click event to follow the hyperlink - it does not negate the fact that the user has clicked the hyperlink (and that click would need to be cancelled). Now it seems that there is no Cancel option for FollowHyperlink event. Therefore I suggest this approach:

Adapted from here: https://www.ozgrid.com/forum/forum/...isable-hyperlink-from-opening-until-confirmed

Rather than have the hyperlink address point to the file, have the link point back to the parent cell (i.e. itself). Then you can use the ScreenTip to hold the actual destination address. The following code will follow the address in the ScreenTip. This code belongs in the relevant sheet module.
Code:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    Dim strAddress          As String
    
    Application.EnableEvents = False
    
    strAddress = Target.Address


    If CBool(Len(strAddress)) Then
        If MsgBox(Prompt:="Follow hyperlink?", Buttons:=vbYesNo + vbQuestion, Title:="Hyperlink Activated") = vbYes Then
            Call ThisWorkbook.FollowHyperlink(Address:=strAddress)
        End If
    End If
    
    Application.EnableEvents = True
End Sub

I will give this a try. But there might be an issue because I have a double click event set up to expand/unhide hidden rows below.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

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