Why are cookies unrecognized when a link is clicked from an external source (i.e. Excel, Word, etc…)

后端 未结 17 2547
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 04:39

I noticed that when a link is clicked externally from the web browser, such as from Excel or Word, that my session cookie is initially unrecognized, even if the link opens u

17条回答
  •  清酒与你
    2020-11-28 04:53

    Here's a VBA fix, for Excel. The same concept can be applied for Microsoft Word. Basically, rather than firing off the link from within Excel, the code executes the link from within a shell. Here's the code:

    Private Sub Worksheet_FollowHyperlink(ByVal objLink As Hyperlink)
        Application.EnableEvents = False
        Dim strAddress As String
        strAddress = "explorer " & objLink.TextToDisplay
        Dim dblReturn As Double
        dblReturn = Shell(strAddress)
        Application.EnableEvents = True
    End Sub
    
    1. For the Excel sheet that contains the links, right-click the sheet tab and click View Code. The VBA editor appears.
    2. Paste the code into the window, and close the editor.
    3. Modify each link in the page so it simply points back to the cell that it is in. To do so:
    4. Right-click the link, and click Edit Hyperlink. An Edit Hyperlink window appears.
    5. Click Place In This Document.
    6. Click the sheet name.
    7. For Type the cell reference, enter a cell reference (e.g. A4).
    8. Click OK.

    A couple of notes:

    • You will need to save the spreadsheet as a macro-enabled spreadsheet (.xlsm). When users open the spreadsheet, they will be asked to enable macros. If they answer No, the links will not work.
    • These instructions are based on Excel 2010. Presumably later versions are similar.

提交回复
热议问题