Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8667273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:55:35+00:00 2026-06-12T17:55:35+00:00

Using VBA 2007, how can I create a Word document from Excel and write

  • 0

Using VBA 2007, how can I create a Word document from Excel and write text of different headings (heading1, heading2, normal) so that the headings would appear in the document map?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:55:36+00:00Added an answer on June 12, 2026 at 5:55 pm

    This example will run from Excel. It uses Early Binding so you need to ensure you have a reference to Word set in the VBA References (Tools->References).

    Word can be a fickle best with putting text in the document. Generally it needs to go a the currently selected point. You can use Bookmarks and/or field codes to put text in different locations within a document.

    Sub MakeWordDocumentWithHeadings()
    
        Dim wdApp As Word.Application, wdDoc As Word.Document
    
        'Use on error resume next so VBA doesn't produce an error if it can't find Word Open
        On Error Resume Next
        Set wdApp = GetObject(, "Word.Application")
    
        'If it is nothing the open a new instance of word
        If wdApp Is Nothing Then Set wdApp = New Word.Application
        'Reset the errors
        On Error GoTo 0
    
        'Add a new document    
        Set wdDoc = wdApp.Documents.Add
    
        'Word works by the location of the 'selection'
        wdApp.Selection.Style = ActiveDocument.Styles("Heading 1")
        wdApp.Selection.TypeText Text:="Heading One"
        wdApp.Selection.TypeParagraph
        wdApp.Selection.Style = ActiveDocument.Styles("Heading 2")
        wdApp.Selection.TypeText Text:="Heading Two"
        wdApp.Selection.TypeParagraph
        wdApp.Selection.Style = ActiveDocument.Styles("Heading 3")
        wdApp.Selection.TypeText Text:="Heading Three"
        wdApp.Selection.TypeParagraph
    
        'Save close or whatever here
    
        'Always set objects to nothing.  
        Set wdDoc = Nothing
        Set wdApp = Nothing
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I want to run a VBA script from Excel 2007 that can switch focus
Using Excel 2007 VBA Have a sheet Dashboard, have other sheets but some special
Using Access 2007 vba addressing an Excel 2007 workbook (WB).... This routine adds a
I am using VBA for Microsoft Excel 2007. My code is as follows: Sub
I am programmatically generating Office Documents (in my case Word or Excel 2007) using
Using VBA, can I find out the value of a text (combobox) control on
Is it possible to extract all of the VBA code from a Word 2007
I am using VBA to paste charts/graphs from Access to PowerPoint. Once pasted, I
Does anyone know how to clear the immediate window using VBA? While I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.