Excel to Word with VBA - .font.size error

Frankie Sharp

New Member
Joined
Aug 3, 2014
Messages
1
Hello,
I'm new to VBA and am having trouble setting the size of a string that is being passed to a new word document using excel. I keep getting the error: Run-time error '5843': Method 'Size' of object '_Font' failed. I am using Office 2011.
Code:
Option Explicit


Sub CreateBasicWordReport()

    Dim wdApp As Word.Application

    Set wdApp = New Word.Application

    With wdApp
    
        .Visible = True 
        .Activate 
        .Documents.Add 
        
        With .Selection
            .ParagraphFormat.Alignment = wdAlignParagraphCenter
            .Font.Bold = True
            .Font.Size = 14
            .TypeText "Top Movies of 2012" 
            .Font.Bold = False
            .TypeParagraph
            .ParagraphFormat.Alignment = wdAlignParagraphLeft
            .TypeParagraph
            
        End With
        
    End With


End Sub

Help would be greatly appreciated!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi Frankie,

I'm just guessing, but I suspect that to set the font size you must have some text (at least one character) selected. In your code above this doesn't appear to be the case.

Damon
 
Upvote 0

Forum statistics

Threads
1,216,094
Messages
6,128,785
Members
449,468
Latest member
AGreen17

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