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 February 14th, 2005, 10:00 AM
Authorized User
Join Date: Feb 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default open, change a excel document from word

i want to get some info out of a excel document into Word.
I have found the next code on the internet:

Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True

Set xlWB = xlApp.Workbooks.Open("C:\Foldername\Filename.xls")
With xlWB.Worksheets(1)

end with
xlWB.Close False

only when i run the procedure i get the next compile error:

user - defined type not defined

on the line : Dim xlWB As Excel.Workbook

how can i prevent this?
Old February 14th, 2005, 11:01 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts

Just make a reference to 'Microsoft Excel xx.0 Object Library' from Tools-References in the VBA editor.
Old February 14th, 2005, 11:23 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts

If you want to copy a range from Excel, try change your code a little:

Sub FromWord_CopyPasteExcelRange()
Dim xlApp As excel.Application
Dim xlWkBk As excel.Workbook
Dim xlWkSht As excel.Worksheet
Dim xlRng As excel.Range

Set xlApp = CreateObject("Excel.Application")
Set xlWkBk = xlApp.Workbooks.Open("j:\book2.xls")
Set xlWkSht = xlWkBk.Worksheets("Sheet1")

Set xlRng = xlWkSht.Range("A1:C3")
    Selection.PasteAndFormat (wdPasteDefault)

xlWkBk.Close False

End Sub

Similar Threads
Thread Thread Starter Forum Replies Last Post
Office Automation- open word document ayazhoda Access VBA 2 November 4th, 2008 12:01 PM
open word document and insert data PorcupineRabbit Visual Basic 2005 Basics 1 August 9th, 2007 06:31 PM
open excel document in jsp page mermaid VB How-To 1 December 3rd, 2004 06:45 PM
Cannot open Word Document At Client Side leo_ling Classic ASP Basics 6 July 1st, 2004 12:31 AM
How to open word document using ASP and read ksaleemkhan Classic ASP Components 3 April 28th, 2004 04:43 PM

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