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:

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,790
Office Version
365
Platform
Windows
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/help-forums/excel-general/68124-disable-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:

danielpalfrey

New Member
Joined
Nov 21, 2018
Messages
17
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
 

danielpalfrey

New Member
Joined
Nov 21, 2018
Messages
17
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/help-forums/excel-general/68124-disable-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.
 

Forum statistics

Threads
1,085,884
Messages
5,386,553
Members
402,006
Latest member
stringer47

Some videos you may like

This Week's Hot Topics

Top