Runtime error trying to create a bulleted list in Word using Excel VBA

bkirtland

New Member
Joined
Nov 30, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
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:

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!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Maybe this.
VBA Code:
        Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
        wdApp.ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:= _
        False, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
        wdWord10ListBehavior
 
Upvote 0

Forum statistics

Threads
1,216,037
Messages
6,128,440
Members
449,453
Latest member
jayeshw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top