Try swapping the below:
For Each CC In WordDoc.ContentControls
If CC.Title = ActiveWorkbook.Names("hello").Name Then
CC.Range.Text = Range("hello").Text
End If
Next
For
On Error Resume Next
For Each CC In WordDoc.ContentControls
If CC.Title = ActiveWorkbook.Names(CC.Title).Name Then
CC.Range.Text = Range(CC.Title).Text
End If
Next
On Error GoTo 0
Or you could use a UDF to check if the range exists on the active sheet:
Function RangeExists(R As String) As Boolean
Dim Test As Range
On Error Resume Next
Set Test = ActiveSheet.Range(R)
RangeExists = Err.Number = 0
End Function
And use it like:
Sub Populate_ContentControls_in_embeded_document()
Dim WordApp As Object
Dim WordDoc As Object
Dim CC As ContentControl
Set WordApp = GetObject(, "Word.Application")
Set WordDoc = WordApp.Documents("Dokument v " & ActiveWorkbook.Name) 'example of embeded document name: "Dokument v AAA_ZAKÁZKA.xlsm"
For Each CC In WordDoc.ContentControls
If RangeExists(CC.Title) Then
CC.Range.Text = Range(CC.Title).Text
End If
Next
End Sub
All of above is untested.