Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Excel Automation with Access 2007

Posted on 2008-10-15
6
Medium Priority
?
736 Views
Last Modified: 2013-11-27
The following protion of code worked perfect with Access 2003 and after I updated 2003 to 2007. Now we have new computers with a fresh install of Office 2007 and now I get Run-time error '-2147417851 (80010105)': Method 'Add' of object 'Workbooks' failed when the compiler tries to add a workbook (Set objWB = objXL.Workbooks.Add). I saw another post about early and late binding so I tried:
Set objWB = objXL.Workbooks
objWB.Add
but that didn't work either.  

I added all the references that were added in 2003 except of course the Office references are now 12 instead of 11.

If anyone knows what may be causing this I would greatly appreciate some assistance.

Dim objXL As Object
    Dim objWB As Object
    Dim strReportName As String
 
    strReportTitle = "Report Name"
      
    'Create a new excel document
    Set objXL = CreateObject("Excel.Application")
    
    'To create new workbook
    Set objWB = objXL.Workbooks.Add 'This now creates the error. With or without parenthesis () at the end.
    objWB.Sheets(1).Name = strReportName

Open in new window

0
Comment
Question by:OpieTaylor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 22723621
The only error I got was on:

strReportTitle = "Report Name"

It should be :

strReportName = "Report Name"

I also added the line below to see the results:

objXL.Visible = True

See the code snippet for the code that works for me in Access 2007 and Excel 2007.
Public Sub Test()
    Dim objXL As Object
    Dim objWB As Object
    Dim strReportName As String
    strReportName = "Report Name"
    'Create a new excel document
    Set objXL = CreateObject("Excel.Application")
    objXL.Visible = True
    'To create new workbook
    Set objWB = objXL.Workbooks.Add
    objWB.Sheets(1).Name = strReportName
End Sub

Open in new window

0
 

Author Comment

by:OpieTaylor
ID: 22728201
Thanks but making it visible before adding a workbook resulted in the same error message. Besides, I don't want the user to see Excel until after the workbook is added. I only want them to see the end result.
Did you execute this code with Access 2007? If so, did you upgrade from a previous version of Access? This code works fine on computers upgraded from previous versions of office but not on brand new machines that  have 2007 installed without upgrades.
0
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 22730010
My machine had Office 2007 SP1 installed on Vista Enterprise from the beginning. I executed the code in a module in Access 2007. We tried adding Office 2000 to my computer but Access 2000 quits working after the first time I use Access 2007.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:OpieTaylor
ID: 22738329
It must have something to do with Windows XP then. I'm running Office 2007 SP1 on XP SP3.
0
 

Accepted Solution

by:
OpieTaylor earned 0 total points
ID: 22783537
I figured out th problem.
A program called "ApproveIt" added the following registry key: HKEY_CURRENT_USER\Software\Microsoft\Office\Excel\Addins\ADTAPILib.ApproveItAddin
and set the load behavior to 3. If I delete this key or change it to a value other than 3, everything works fine.
So ApproveIt is the problem...
Thanks for you help.
0
 

Expert Comment

by:KevinS2112
ID: 34176874
I had the same problem in Word where I was getting the same error, but on the doc.SaveAs method.

I removed the ApproveIt add-in and got rid of the problem.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question