Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 29th, 2013, 06:18 AM
Registered User
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel 2002 VBA: Chpy 19 - loading word?

I purchased the book in the title above, and was working through some of the code and found that following code from chapter 19 does not work;
Sub CopyTableToWordDocument()
   'Example of Word automation using early binding
   'Copies range from workbook and appends it to existing Word document
   Dim wdApp As Word.Application

   'Copy A1:B6 in Table sheet

   'Establish link to Word
   Set wdApp = New Word.Application
   With wdApp
      'Open Word document
      .Documents.Open Filename:="C:\VBS\Books\WROX Excel 2002 VBA\MyDoc.doc"
      With .Selection
         'Go to end of document and insert paragraph
         .EndKey Unit:=wdStory
         'Paste table

      End With
      'Exit Word
   End With
   'Release object variable
   Set wdApp = Nothing
End Sub
I get the following runtime error;

Run-time error '-2417417851 (80010105)':
Automation Error
The server threw an exception

The debuger stops at the line with the code;
.Documents.Open Filename:="C:\VBS\Books\WROX Excel 2002 VBA\MyDoc.doc"
Does anyone know what this error means and what I can do to stop it?
Old January 29th, 2013, 06:33 AM
Registered User
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

#i would just like to point out that the above code was downloaded from the Wrox website in the spreadsheet format and ran from the spreadsheet that contained it.

However, since then, I have copied and pasted the same section of code above into another independent spreadsheet and run from there.

This time, though, I get another error message that says;
Compile Error
User-defined type not defined

The debuger stops at this line of code;
Dim wdApp As Word.Application
The code looks Ok to me.
Am I missing something obvious?

Last edited by scooble; January 29th, 2013 at 06:43 AM..
Old February 14th, 2013, 11:16 AM
Registered User
Join Date: Feb 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Loading to Word from Excel

Hi scooble,

have you referenced the Word Object library in VBA?

In VBA go to Tools-->References. Look for and apply a check next to
Microsoft Word xx.x Object Library.

hope this helps

Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing Marker color in Excel 2002 vba boulder_dude2000 Excel VBA 0 February 3rd, 2009 03:20 PM
Excel 2002 VBA Programmer's Reference hawlk VB How-To 0 February 4th, 2007 04:35 PM
Suspected Error in "Excel 2002 VBA" book rstober Excel VBA 7 September 2nd, 2004 05:48 PM
A simple question about date in VBA for Excel 2002 Trancefuzion Excel VBA 2 July 29th, 2004 04:37 AM
Excel 2002 VBA Programmers Guide quinoman Wrox Book Feedback 1 June 9th, 2003 09:07 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.