Word VBA to access 'Linked Object > Edit Link' path in Context Menu

jdarner

New Member
Joined
Sep 7, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Thanks in advance! I have countless Excel links in a Word document that are used to generate reports. To jump (from Word) to the source of the link (in Excel) I typical right-click on the link, select 'Linked Object' form the Context, then select 'Edit Path' or 'Open Link'

I would like to be able to jump to the Excel location using Word VBA so that I can assign a button and create a shortcut key. Seems easy enough, right? After countless attempts and searching I have found no solution. Any advice or code is greatly appreciated!
 

Attachments

  • Screenshot 2024-09-07 092658.jpg
    Screenshot 2024-09-07 092658.jpg
    23.5 KB · Views: 1

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Well, writing the question out spurred a alternate approach that appears to have solved this:
Sub SelectAndOpenLinkedFields()
Dim fld As Field
Dim rng As Range
Dim selectedField As Field
Dim fieldFound As Boolean

' Get the current selection
Set rng = Selection.Range

fieldFound = False

' Loop through all fields in the document to find the one the cursor is in
For Each fld In ActiveDocument.Fields
If fld.Type = wdFieldLink Then
' Check if the cursor is within the range of this field
If rng.InRange(fld.Code) Or rng.InRange(fld.Result) Then
fld.Select ' Select the entire linked field
fieldFound = True
Exit For
End If
End If
Next fld

If fieldFound Then
' After selecting the linked field, attempt to open the linked object
Set rng = Selection.Range
On Error Resume Next
Set selectedField = rng.Fields(1)
On Error GoTo 0

If Not selectedField Is Nothing Then
If selectedField.Type = wdFieldLink Then
selectedField.OLEFormat.DoVerb wdOLEVerbOpen
Else
MsgBox "The selected field is not a linked object. Please place the cursor inside a linked field.", vbExclamation, "Header"
End If
Else
MsgBox "No linked object found in the selected field. Ensure you're selecting a linked object.", vbCritical, "Header"
End If
Else
MsgBox "No linked field was found where the cursor is placed. Please ensure you are inside a linked field and try again.", vbInformation, "Header"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,114
Members
452,302
Latest member
TaMere

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