Run-time error 424 "object required" on line with ThisComponent

I got a macro code from the Internet for Microsoft Word 2021 software, and when I implement it in Microsoft Word, I get an error! Does anyone know where the problem comes from?

ERROR:

Here's the error message:

Error424_img 1

And it cccurs on the following line:

Error424_img 2

CODE:

Sub ChangeTashkeelColors()
 CrRepDesc = ThisComponent.createReplaceDescriptor
 CrRepDesc.searchRegularExpression = True
 CrRepDesc.searchString = "?" ' Unicode Character 'ARABIC FATHA' (U+064E) or Shift+q on the Arabic keyboard
 FnAllRepDesc = ThisComponent.findAll(CrRepDesc)
 For i = 0 To FnAllRepDesc.Count - 1
     FoundTxt = FnAllRepDesc.getByIndex(i)
     FoundTxt.CharColor = 1400606  ' Dark Green Color
 Next i
 CrRepDesc = ThisComponent.createReplaceDescriptor
 CrRepDesc.searchRegularExpression = True
 CrRepDesc.searchString = "?" ' Unicode Character 'ARABIC FATHATAN' (U+064B) or Shift+w on the Arabic keyboard
 FnAllRepDesc = ThisComponent.findAll(CrRepDesc)
 For i = 0 To FnAllRepDesc.Count - 1
     FoundTxt = FnAllRepDesc.getByIndex(i)
     FoundTxt.CharColor = 9498256 ' Light Green Color
 Next i
 CrRepDesc = ThisComponent.createReplaceDescriptor
 CrRepDesc.searchRegularExpression = True
 CrRepDesc.searchString = "?" ' Unicode Character 'ARABIC DAMMA' (U+064F) or Shift+e on the Arabic keyboard
 FnAllRepDesc = ThisComponent.findAll(CrRepDesc)
 For i = 0 To FnAllRepDesc.Count - 1
     FoundTxt = FnAllRepDesc.getByIndex(i)
     FoundTxt.CharColor = 9109504 ' Dark Red Color
 Next i
 CrRepDesc = ThisComponent.createReplaceDescriptor
 CrRepDesc.searchRegularExpression = True
 CrRepDesc.searchString = "?" 'Unicode Character 'ARABIC DAMMATAN' (U+064C) or Shift+r on the Arabic keyboard
 FnAllRepDesc = ThisComponent.findAll(CrRepDesc)
 For i = 0 To FnAllRepDesc.Count - 1
     FoundTxt = FnAllRepDesc.getByIndex(i)
     FoundTxt.CharColor = 16764107 ' Light Red Color
 Next i
 CrRepDesc = ThisComponent.createReplaceDescriptor
 CrRepDesc.searchRegularExpression = True
 CrRepDesc.searchString = "?" ' Unicode Character 'ARABIC KASRA' (U+0650) or Shift+a on the Arabic keyboard
 FnAllRepDesc = ThisComponent.findAll(CrRepDesc)
 For i = 0 To FnAllRepDesc.Count - 1
     FoundTxt = FnAllRepDesc.getByIndex(i)
     FoundTxt.CharColor = 139 ' Dark Blue Color
 Next i
 CrRepDesc = ThisComponent.createReplaceDescriptor
 CrRepDesc.searchRegularExpression = True
 CrRepDesc.searchString = "?" ' Unicode Character 'ARABIC KASRATAN' (U+064D) or Shift+s on the Arabic keyboard
 FnAllRepDesc = ThisComponent.findAll(CrRepDesc)
 For i = 0 To FnAllRepDesc.Count - 1
     FoundTxt = FnAllRepDesc.getByIndex(i)
     FoundTxt.CharColor = 11393254 ' Light Blue Color
 Next i
 CrRepDesc = ThisComponent.createReplaceDescriptor
 CrRepDesc.searchRegularExpression = True
 CrRepDesc.searchString = "?" ' Unicode Character 'ARABIC SUKUUN' (U+0652) or Shift+x on the Arabic keyboard
 FnAllRepDesc = ThisComponent.findAll(CrRepDesc)
 For i = 0 To FnAllRepDesc.Count - 1
     FoundTxt = FnAllRepDesc.getByIndex(i)
     FoundTxt.CharColor = 16753920 ' Orange Color
 Next i
 CrRepDesc = ThisComponent.createReplaceDescriptor
 CrRepDesc.searchRegularExpression = True
 CrRepDesc.searchString = "?" ' Unicode Character 'ARABIC SHADDA' (U+0651) or Shift+^ on the Arabic keyboard
 FnAllRepDesc = ThisComponent.findAll(CrRepDesc)
 For i = 0 To FnAllRepDesc.Count - 1
     FoundTxt = FnAllRepDesc.getByIndex(i)
     FoundTxt.CharColor = 6950317 ' Purple Color
 Next i
 End Sub

This code is for changing the color of several diacritics in one word. An error is encountered while running.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation