Here is the code i have in Excel to control a word document, and publish it with some data. I would like to create some of the text in different styles, but keep getting Run time error 430 (Class does not support Automation or does not support expected interface)
Here is the code:
'Create the word document
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
objWord.Visible = True
Set objSelection = objWord.Selection
For i = 2 To 94
'Heading 1
If myRange(i - 1, 1) <> myRange(i, 1) Then
objSelection.TypeParagraph
objSelection.Style = ActiveDocument.Styles("Heading 2")
objSelection.TypeText Text:=myRange(i, 1)
End If
objSelection.TypeParagraph
objSelection.Style = ActiveDocument.Styles("Heading 3")
objSelection.TypeText Text:=myRange(i, 2)
For k = 3 To 12
objSelection.TypeParagraph
objSelection.Style = ActiveDocument.Styles("Heading 4")
objSelection.TypeText Text:=myRange(1, k)
objSelection.TypeParagraph
objSelection.Style = ActiveDocument.Styles("Normal")
objSelection.TypeText Text:=myRange(i, k)
Next
Next
myRange
variable, is that a Excel.Range object? if its is, you are not providing correct value for the object. Looks like you are usingRange
as aCell
. Also, there is a Word library you can reference in Excel VBA. Finally, as Dirk said, please specify where the error occurs – ZacobjSelection.Style = ActiveDocument.Styles("___")
. which is not working. The rest is working just fine. – user3016795