Create New Word Document

Posted on 2011-05-01
Last Modified: 2012-05-11

I am doing a small simple project where I am creating a Word Document (i'll call it Doc1) which will hold all the VBA/Macro code to create a new Word Document (i'll call it Doc2) partly based on information they have typed into User Form within Doc1; for example the User Form in Doc 1 will ask the user for a Document title. The user will enter the title of the document and click a create button which will create a new Word Document (Doc2) and add into it the title the user has entered into the User Form from Doc 1.

This appears very simple. However can anyone please point me in the right direction of the following; I am ok with creating and capturing all the information in the text fields on the User Form (Doc1) its just the creation of the document that I need help with.

1. How can I create a new Word Document and name it Doc2.docx and save it to my desktop?
2. Once the document has been created; add the title as entered into my User Form from Doc1?

Thanks in advance,


Question by:gisvpn
    LVL 76

    Assisted Solution

    Note that VBA projects are usually in templates, rather than documents.

    To name a document, you must save it.

    Sub NewDoc()
        Dim Doc As Document
        Set Doc = Documents.Add '(TemplatePath) if not Normal
        Doc.SaveAs "C:\MyFolder\" & TextBox1.Text & ".Docx"
    End Sub

    Open in new window

    LVL 23

    Accepted Solution

    - i would assume you have a module and a form called UserForm1, a textbox and a command button to click on for creation of a new document:

    -- this is on Modules. call to display UserForm1 :
    Sub NewDoc()
    End Sub

    Open in new window

    -- this is on UserForm1 which contain a textbox called Textbox1 and command button called CommandButton1.:

    Private Sub CommandButton1_Click()
      Set objWord = CreateObject("Word.Application")
      objWord.Caption = "This is Word Caption"
      objWord.Visible = True
      Set objDoc = objWord.Documents.Add()
      Set objSelection = objWord.Selection
      objSelection.Font.Name = "Arial"
      objSelection.Font.Size = "18"
       'this will display the title on the document
      objSelection.TypeText "Title: " & UserForm1.TextBox1.Text   
      'change the <profilename> below to your windows login profile id. 
      'test to open the desktop folder by typing the whole folder name on windows explorer 
      objDoc.SaveAs ("C:\Documents and Settings\profilename\Desktop\doc2.docx") 
    End Sub

    Open in new window

    LVL 76

    Expert Comment

    Yes, the use of the word 'Title' is a little ambiguous in Word.

    There is a built-in Title property. It could mean the first text, probably with a Heading 1 style, or it could be the stem of the document's file name (or even all three).

    Author Closing Comment

    Perfect thanks!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
    This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
    This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
    The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now