Word

As seen in the article of Outlook or PowerPoint, we can create ActiveX objects which allows creating objects from other applications of the system.

We can create a Word document through VBA macro. Through an automatic analyzes of your Excel data, you can automatically write a report in the form of a Word document.

Word Logo

Create a Word document in VBA

To create a Word document, you must first use the CreateObject function which creates and returns a reference to an ActiveX object. This Word application has the mains properties of a document.

Sub CreateWordDocument()
'Create a  Word document

    Dim WordApp, WordDoc, WordLayout, WordSlide, Sh, NbShpe As Object
    
    'Open the Word application
    Set WordApp = CreateObject("Word.Application")
    WordApp.Visible = True
    'Create a new Word Document
    Set WordDoc = WordApp.Documents.Add
    
    'Create a Text Zone
    Set Sh = WordDoc.Shapes.AddLabel(Orientation:=msoTextOrientationHorizontal, _
        Left:=100, Top:=100, Width:=150, Height:=60)
        
    'Insert the value in A1 in the text zone
    Sh.TextFrame.TextRange.Text = Range("A1")
    
    'Modify colot text
    Sh.TextFrame.TextRange.Font.Color = RGB(255, 100, 255)
    
End Sub
Word document and Excel workbook

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s