Hi all,
I am trying to create a word document with inputs from Excel. Everything has been working well until I tried to create a bulleted list. The relevant portion of my code is posted below:
Everything works great until when I try to turn bullets on. I opened up Microsoft Word and recorded a macro of turning bullets on and off, and copied and pasted the generated code into my Excel VBA code, but it keeps getting hung up on:
The error I get is:
Run-time error '-2147023170 (800706be)':
Automation error
The remote procedure call failed.
Any insights anyone can provide would be greatly appreciated!
I am trying to create a word document with inputs from Excel. Everything has been working well until I tried to create a bulleted list. The relevant portion of my code is posted below:
VBA Code:
Set wdApp = New Word.Application
With wdApp
.Visible = True
.Activate
.Documents.Add
With .Selection
'Create the header
.ParagraphFormat.Alignment = wdAlignParagraphCenter 'center the text
.BoldRun 'switch bold on
.Font.Size = 16
.Font.Name = "Arial"
.TypeText "Header Text"
.TypeParagraph 'enter a new line
.TypeText "Sub-header Text"
.TypeParagraph
'Record the inputs
.TypeParagraph
.Font.Size = 12
.BoldRun 'switch bold off
.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Font.Underline = wdUnderlineSingle 'underline
.TypeText "Inputs:"
.TypeParagraph
.Font.Size = 10
.Font.Underline = wdUnderlineNone 'turn off underline
.TypeText "Number of Spans = " & num_spans
.TypeParagraph
.TypeText "Maximum Span Length (ft) = " & max_span_length
.TypeParagraph
.TypeText "Horizontal Curvature Radius (ft) = " & curve_rad
.TypeParagraph
.Font.Size = 8
.ItalicRun 'switch italics on
.TypeText "(Note that straight bridges will report a radius of 99,999 ft)"
.TypeParagraph
.Font.Size = 10
.ItalicRun 'switch italics off
.TypeText "Skew Angle (deg) = " & skew_angle
.TypeParagraph
.TypeText "Severity of vertical curve = " & vert_curve
.TypeParagraph
.TypeParagraph
.TypeText Intro
.TypeParagraph
.TypeParagraph
.TypeText "The identified possible appropriate structure types based on your inputs are the following:"
End With
For i = 1 To numtypes
With .Selection
.TypeParagraph
.TypeText struct_type(i)
End With
Next i
.Selection.TypeParagraph
.Selection.TypeParagraph
For i = 1 To numtypes
If struct_type(i) = "Adjacent Prestressed Concrete Deck Beams" Then
With .Selection
.BoldRun 'turn bold on
.TypeText "Adjacent Prestressed Concrete Deck Beams"
.TypeParagraph
.BoldRun 'turn bold off
.TypeText adj_deck_text
.TypeParagraph
.TypeText "Pros:"
.TypeParagraph
End With
'Turn bullets on
ListGalleries(wdBulletGallery).ListTemplates(1).Name = ""
.Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:= _
False, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
wdWord10ListBehavior
'Report the pros
For j = 1 To 5
With .Selection
.TypeText adj_deck_pros(j)
.TypeParagraph
End With
Next j
'turn bullets off
.Selection.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
.Selection.TypeText "Cons:"
.Selection.TypeParagraph
'Turn bullets on
ListGalleries(wdBulletGallery).ListTemplates(1).Name = ""
.Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:= _
False, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
wdWord10ListBehavior
'Report the cons
For j = 1 To 6
With .Selection
.TypeText adj_deck_cons(j)
.TypeParagraph
End With
Next j
'turn bullets off
.Selection.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
End If
Next i
End With
Everything works great until when I try to turn bullets on. I opened up Microsoft Word and recorded a macro of turning bullets on and off, and copied and pasted the generated code into my Excel VBA code, but it keeps getting hung up on:
VBA Code:
.Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:= _
False, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
wdWord10ListBehavior
The error I get is:
Run-time error '-2147023170 (800706be)':
Automation error
The remote procedure call failed.
Any insights anyone can provide would be greatly appreciated!