Question : Update values linked to excel cell within embedded word object with a VBA

To update the linked return values within the embedded word object in attached file. I have everytime to open the embedded object, click yes to update values and close it again. I am looking for solution in the form of a VBA code to automate this process.

(For formatting purposes and because the text is part of a larger comment within an excel sheet, this cannot be done with a text solution within excel, only with embedded word object)

Thanks for your help in advance!

Answer : Update values linked to excel cell within embedded word object with a VBA

stmoritz, think I've got what you want. try this code.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
Sub UpdateReturnsInMonthlyComment()
    On Error Resume Next
    
    Dim w As Object
    Dim prevUpdateLinksAtOpen As Boolean
    Dim i As Integer
    
    Application.ScreenUpdating = False
    ActiveSheet.Shapes("MonthlyComment").Select
        
    Set w = GetObject("Word.Application")
    If Err.Number <> 0 Then
        Set w = CreateObject("Word.Application")
    End If
    
    prevUpdateLinksAtOpen = w.Options.UpdateLinksAtOpen
    w.Options.UpdateLinksAtOpen = False
    
    Selection.Verb Verb:=xlPrimary
    For i = 1 To w.ActiveDocument.Fields.Count
        w.ActiveDocument.Fields(i).Update
    Next i
    
    w.Options.UpdateLinksAtOpen = prevUpdateLinksAtOpen
    w.Quit
    Set w = Nothing
End Sub
Random Solutions  
 
programming4us programming4us