title: How to return focus to Word document from where the macro opened Excel file
body: <pre><code>Private Sub CommandButton1_Click()
  Dim oRng As Word.Range
  Dim arrExcelValues()
  Dim i As Long
  Dim x As Long
  
  Set objExcel = CreateObject("Excel.Application")
  Set objWorkbook = objExcel.Workbooks.Open("C:\Risk Words.xlsx")
  objExcel.Visible = False
  
  i = 1
  x = 0
  
  Do Until objExcel.Cells(i, 1).Value = ""
     ReDim Preserve arrExcelValues(x)
     arrExcelValues(x) = objExcel.Cells(i, 1).Value
     i = i + 1
     x = x + 1
  Loop
  objExcel.Quit
  
  For i = 0 To UBound(arrExcelValues)
      Set oRng = ActiveDocument.Range
      Options.DefaultHighlightColorIndex = wdYellow
      With oRng.Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Text = arrExcelValues(i)
          .MatchWholeWord = True
          .Replacement.Highlight = True
          .Execute Replace:=wdReplaceAll
      End With
  Next
  End Sub
  </code></pre>
  
  <p>Wrote this code to pick words from the Excel file and check it in the Word file to see if they are present and highlight them. However, it does not seem to work from Set oRng = ActiveDocument.Range. Although, if I put a MsgBox before that, it does show the values picked up from the Excel and store in the array.</p>