+ Reply to Thread
Results 1 to 7 of 7

Opening Word Template(.dot) with Excel VBA - RUNTIME ERROR

  1. #1
    Registered User
    Join Date
    07-10-2009
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    20

    Opening Word Template(.dot) with Excel VBA - RUNTIME ERROR

    Hey,

    I am trying to open a .dot file using a macro in Excel 2007.

    Check out Microsoft's website for an example.

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

    The code breaks at:
    Please Login or Register  to view this content.

    I get the following error:
    Please Login or Register  to view this content.

    I believe the code works fine in 2003, but not in 2007.

    In order to get it to work, I need to open the template.dot file first and then run the macro.


    I'm using the following references:
    - Visual Basic For Applications
    - Microsoft Excel 12.0 Object Library
    - OLE Automation
    - Microsoft Office 12.0 Object Library
    - Microsoft Forms 2.0 Object Library
    - Microsoft Word 12.0 Object Library




    Any ideas?

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Opening Word Template(.dot) with Excel VBA - RUNTIME ERROR

    Hello Wildjester,

    You have either assign an existing Word document to your object or create a new one. Which are you doing?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    07-10-2009
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Opening Word Template(.dot) with Excel VBA - RUNTIME ERROR

    Quote Originally Posted by Leith Ross View Post
    Hello Wildjester,

    You have either assign an existing Word document to your object or create a new one. Which are you doing?
    The template.dot exists already. I specify where the file is found here:
    Please Login or Register  to view this content.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Opening Word Template(.dot) with Excel VBA - RUNTIME ERROR

    Hello Wildjester,

    I don't have Office 2007 and have tried looking up this automation error, but nothing. The code looks correct from a 2003 standpoint. Perhaps someone else who has Office 2007 can help you.

  5. #5
    Registered User
    Join Date
    07-10-2009
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Opening Word Template(.dot) with Excel VBA - RUNTIME ERROR

    Alright, thanks anyways...



    Any 2007 users out there??

  6. #6
    Registered User
    Join Date
    07-10-2009
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Opening Word Template(.dot) with Excel VBA - RUNTIME ERROR

    Any ideas???

  7. #7
    Registered User
    Join Date
    04-04-2011
    Location
    Peoria, AZ
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Opening Word Template(.dot) with Excel VBA - RUNTIME ERROR

    I am using the following:

    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = True
    strTemplateName = [build your full path & filename here]
    Set wrdDoc = wrdApp.Documents.Open(strTemplateName)

    This works BUT it opens the template as the template, not as a new document based on that template. I am still looking for how to do that. maybe your issue is trying to open a 2003 template (.dot) instead of a 2007 template (.dotx)?

    PS - found the answer to my quest if you're curious: use .Add with the template filename instead of .Open and a new document based on that template is created.
    Last edited by Nani413; 04-04-2011 at 04:23 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1