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:

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,798
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/...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:

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/...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.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,099
Messages
5,484,660
Members
407,460
Latest member
Fakxi

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top