add hyperlink in Word to network printer

81 Views Asked by At

Using Powershell 7.3.6 to add a hyperlink to a Word 2016 doc.

The hyperlink needs to be a network printer like this: \SERVER1\Printer1

When clicking on the link in Word, I get the error, "Cannot open specified file" I can get a website or an email address to work, just not a UNC path. Does anyone know any tips for this?

Thanks, Paul

1

There are 1 best solutions below

0
Dovgal Dima On

To add a hyperlink to a UNC path (\SERVER1\Printer1), you can use the following VBA (Visual Basic for Applications) code:

Sub AddUNCLink()
    ' Define variables
    Dim SelectedText As String
    Dim UNCPath As String

    ' Get the selected text
    SelectedText = Selection.Text

    ' Specify the UNC path
    UNCPath = "\\SERVER1\Printer1"

    ' Create the hyperlink
    ActiveDocument.Hyperlinks.Add _
        Anchor:=Selection.Range, _
        Address:=UNCPath, _
       TextToDisplay:=SelectedText
End Sub