I am using the below mentioned code to copy some values in word and then copying it back to excel.
But getting the
runtime error 429 Activex component can't create object.
This same piece of code was working before I formatted my system. But after the new installations this is not working and I'm getting the error.
Sub Word()
Application.DisplayAlerts = False
Dim ws As Worksheet
Dim Path As String
Dim objWord As Object
Dim objDoc As Object
Path = ActiveWorkbook.Path
Set inv = Workbooks.Open(Path & "\inv.xls")
Set test = Workbooks.Open(Path & "\test.xlsx")
Set ws = inv.Sheets("inv")
Set Wb = test.Sheets("Sheet1")
ws.Range("A1").Copy
Set objWord = CreateObject("Word.Application") <---The error is here
Set objWord.Visible = True
Set objDoc = objWord.Documents.Open(Path & "\test.docx")
objWord.Selection.Paste
Application.CutCopyMode = False
objDoc.Range(0, objDoc.Range.End).Copy
Wb.Range("A1").Select
ActiveSheet.Paste
inv.Close Savechanges:=False
test.Close Savechanges:=True
objWord.ActiveDocument.Close Savechanges:=wdDoNotSaveChange
objWord.Quit
Set objWord = Nothing
Set objDoc = Nothing
End Sub
Wordas that could be misunderstood by VBA. You don't declareinv,wbortest- do you haveOption Explicitat the top of the code module? If not, add it to prevent problems caused by spelling errors and similar. - Cindy MeisterobjWord.ActiveDocument.Close Savechanges:=wdDoNotSaveChange- here you should be using the object you declared for the Word document,objDoc, notActiveDocument. - Cindy Meister