Hi everyone
I am trying to run a code that will search & replace a word in multiple word documents. However, I am always getting the error code 438. i am using excel 2016. Sorry I am a total newbie, so no clue what to do.
It‘s always the first line that is highlighted yellow.
	
	
	
		
thank you!
edit: so i‘ve tried to debug it and i get until .HomeKey Unit:=wdStory
 I am trying to run a code that will search & replace a word in multiple word documents. However, I am always getting the error code 438. i am using excel 2016. Sorry I am a total newbie, so no clue what to do.
It‘s always the first line that is highlighted yellow.
		Code:
	
	
	Sub FindAndReplaceInFolder()
  Dim objDoc As Document
  Dim strFile As String
  Dim strFolder As String
  Dim strFindText As String
  Dim strReplaceText As String
  '  Pop up input boxes for user to enter folder path, the finding and replacing texts.
  strFolder = InputBox("Enter folder path here:")
  strFile = Dir(strFolder & "\" & "*.docx", vbNormal)
  strFindText = InputBox("Enter finding text here:")
  strReplaceText = InputBox("Enter replacing text here:")
  '  Open each file in the folder to search and replace texts. Save and close the file after the action.
  While strFile <> ""
    Set objDoc = Documents.Open(Filename:=strFolder & "\" & strFile)
    With objDoc
      With Selection
        .HomeKey Unit:=wdStory
        With Selection.Find
          .Text = strFindText
          .Replacement.Text = strReplaceText
          .Forward = True
          .Wrap = wdFindContinue
          .Format = False
          .MatchCase = False
          .MatchWholeWord = False
          .MatchWildcards = False
          .MatchSoundsLike = False
          .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
      End With
      objDoc.Save
      objDoc.Close
      strFile = Dir()
    End With
  Wend
End Sub
	thank you!
edit: so i‘ve tried to debug it and i get until .HomeKey Unit:=wdStory
			
				Last edited: