Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-26-2013, 11:57 AM
Pierre-Hugues Pierre-Hugues is offline Need to open an Excel WorkBook from Word VBA Windows 8 Need to open an Excel WorkBook from Word VBA Office 2013
Novice
Need to open an Excel WorkBook from Word VBA
 
Join Date: Jun 2013
Posts: 8
Pierre-Hugues is on a distinguished road
Default Need to open an Excel WorkBook from Word VBA

Hi Guy
I have in the past month created a complex (for me) userform on Word's VBA.
Now that I am all but done I seem to be unable to open an Excel WorkBook
by using the workbooks.add. It gives me an error 424 object required.
I taught that would work like the Word command Documents.add.
Do I need to declare anything?

Do any of you know how I should proceed.

Thanks
Reply With Quote
  #2  
Old 09-29-2013, 06:50 PM
fumei fumei is offline Need to open an Excel WorkBook from Word VBA Windows 7 64bit Need to open an Excel WorkBook from Word VBA Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

It is - sort of - like the Word command Documents.Add.

However, as you have found out, you need an object to do so. An Excel application object. This can be early or late binding. If you do NOT need to worry about version issues, use early binding.

To use early binding you need to first set a Reference to the Excel libraries - this is done in the References menu item in the VBE.

Then you must declare your object variables.

Then you must SET your object variables.

There are lots and lots of examples to be found.
Reply With Quote
  #3  
Old 10-03-2013, 08:41 AM
Pierre-Hugues Pierre-Hugues is offline Need to open an Excel WorkBook from Word VBA Windows 8 Need to open an Excel WorkBook from Word VBA Office 2013
Novice
Need to open an Excel WorkBook from Word VBA
 
Join Date: Jun 2013
Posts: 8
Pierre-Hugues is on a distinguished road
Default

Dim oExcel As Excel.Application
Dim oWB As Workbooks
Set oExcel = New Excel.Application

Set oWB = oExcel.Workbooks.Open("c:\test\Classeur1.xls")

however I get an error 13
at first I used variable to provide the path but since it says type mismatch I changed it to a short location. I even changed from .xlsx to .xls just to be safe but it's still not working. Any suggestion?
Reply With Quote
  #4  
Old 10-04-2013, 05:06 PM
macropod's Avatar
macropod macropod is offline Need to open an Excel WorkBook from Word VBA Windows 7 32bit Need to open an Excel WorkBook from Word VBA Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

This is wrong:
Dim oWB As Workbooks
It should be:
Dim oWB As Workbook
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 10-07-2013, 06:27 AM
Pierre-Hugues Pierre-Hugues is offline Need to open an Excel WorkBook from Word VBA Windows 8 Need to open an Excel WorkBook from Word VBA Office 2013
Novice
Need to open an Excel WorkBook from Word VBA
 
Join Date: Jun 2013
Posts: 8
Pierre-Hugues is on a distinguished road
Default

Thanks for the help guys.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to open an Excel WorkBook from Word VBA #REF! error when opening a workbook that contain a refference to another workbook tanababa Excel 2 06-07-2012 03:11 PM
Range(Cell1,Cell2) Error on another workbook controlling some other workbook? tinfanide Excel Programming 1 02-09-2012 04:08 PM
Need to open an Excel WorkBook from Word VBA Open Word w Excel & fill Word textboxes w info from Excel fields runtime error 4248 Joe Patrick Word VBA 2 01-30-2012 07:23 AM
Shared Excel workbook eguru2 Excel 0 07-12-2011 12:02 AM
Unable to open Excel 97-2003 workbook J Partridge Excel 1 11-07-2010 03:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:47 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft