none
Access VBA to create a Word Document

    Question

  • I am hoping that someone can provide me a link or some advice in creating a Word Document from an Access VBA Application. I have to create some client letters. And I am struggling with a recurring error that I keep receiving. I am dealing with Microsoft Office 2003 and the error is...

    Run-time error '4248':

    This command is not available because no document is open

    I have the following commands in my VBA from other Google searches I've done.

        Dim WordApp As New Word.Application
        Dim WordDoc As New Word.Document
        Dim WordSel As Word.Selection
        Dim WordTable As Table
        Dim WordHeaderFooter As HeaderFooter
       
        Set WordApp = CreateObject("Word.Application")
        WordApp.Visible = True
        Set WordDoc = WordApp.Documents.Add
        WordDoc.Select

       
        With WordDoc
            Set WordHeaderFooter = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary)
        End With

    My problem is that I don't undertstand what all these VBA commands are doing. I know I can make Word visible and watch what it's doing.

    Can anyone help me? Maybe provide me a web site with some example VBA code that creates a Word document with some explanation as to what each command is doing.

    Thanks in advance for your review and am hopeful for a reply.

    PSULionRP

    Monday, March 05, 2012 2:11 PM

Answers

  • My problem is that I don't undertstand what all these VBA commands are doing.

    I take it from your remarks that you've copied this code from elsewhere.

    Do you have a Reference to the "Microsoft Word 14.0 Object Library", or something similar? You should look on the Tools/ References menu. You might need to scroll down that list and tick the box. I need to know whether the box is already ticked [checked] for this reference, or, whether ticking [checking] this box resolves this problem.

    If you need to distribute this application, you might need to know that there are ways of adding references using VBA code. Let me know and I'll provide more information about this too.


    Matthew Slyman M.A. (Camb.)

    • Marked as answer by Bruce Song Tuesday, March 20, 2012 5:06 AM
    Monday, March 05, 2012 4:15 PM
  • Do you need to create some kind of Mail merge?

    In that case you might take a look at Albert D. Kallal example of creating a super easy Word merge, you can download in here:

    http://www.hitechcoach.com/index.php?option=com_docman&task=doc_details&gid=22&Ite..

    Or check his site:

    http://www.kallal.ca/msaccess/msaccess.html

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer as an answer when your question is being answered.

    • Marked as answer by Bruce Song Tuesday, March 20, 2012 5:06 AM
    Monday, March 05, 2012 5:05 PM

All replies

  • My problem is that I don't undertstand what all these VBA commands are doing.

    I take it from your remarks that you've copied this code from elsewhere.

    Do you have a Reference to the "Microsoft Word 14.0 Object Library", or something similar? You should look on the Tools/ References menu. You might need to scroll down that list and tick the box. I need to know whether the box is already ticked [checked] for this reference, or, whether ticking [checking] this box resolves this problem.

    If you need to distribute this application, you might need to know that there are ways of adding references using VBA code. Let me know and I'll provide more information about this too.


    Matthew Slyman M.A. (Camb.)

    • Marked as answer by Bruce Song Tuesday, March 20, 2012 5:06 AM
    Monday, March 05, 2012 4:15 PM
  • Do you need to create some kind of Mail merge?

    In that case you might take a look at Albert D. Kallal example of creating a super easy Word merge, you can download in here:

    http://www.hitechcoach.com/index.php?option=com_docman&task=doc_details&gid=22&Ite..

    Or check his site:

    http://www.kallal.ca/msaccess/msaccess.html

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer as an answer when your question is being answered.

    • Marked as answer by Bruce Song Tuesday, March 20, 2012 5:06 AM
    Monday, March 05, 2012 5:05 PM
  • Do you need to create some kind of Mail merge?

    In that case you might take a look at Albert D. Kallal example of creating a super easy Word merge, you can download in here:

    http://www.hitechcoach.com/index.php?option=com_docman&task=doc_details&gid=22&Ite..

    Or check his site:

    http://www.kallal.ca/msaccess/msaccess.html

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer as an answer when your question is being answered.

    Good day fellow programming community,

    Question: Using Access 2010 VBA, is there a procedure to reference my hotmail (email account) functionality from a custom form in Access application? Similar to the concept of using Outlooks library to reference API "SendObject" etc.?????

    Thank you for being brilliant!

    Marcro

    Friday, March 16, 2012 3:44 PM
  • Good Afternoon Marcro,

    You should ask this question in a new post.


    Chris Ward

    Friday, March 16, 2012 9:06 PM