Solved

Opening a Workbook from Access 2016

Posted on 2016-09-14
3
150 Views
Last Modified: 2016-09-15
Hi,

My client is upgrading from Office 2010 to Office 2016 so I need to get the following code to work but I don't understand why the following won't work.

I am getting the following error unless I set Excel to be visible:

Runtime Error -2147417851 (80010105)
Method 'Open' of object 'Workbooks' failed


dim objXL as Object
Dim objWkb As Object

Set objXL = New Excel.Application
stDealerAC = "ABBEYNW"
'objXL.Visible = True
Set objWkb = objXL.Workbooks.Open("H:\order book\order_status\" & stDealerAC & ".xls")


Question:  How can I get it to run without objXL.Visible = True?
0
Comment
Question by:LJKMartin
[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
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
crystal (strive4peace) - Microsoft MVP, Access earned 500 total points
ID: 41798243
the variables are dimensioned as object so that late binding can be used.  This statement, however, requires early binding:
Set objXL = New Excel.Application
Instead, use
 Set objXL = CreateObject("Excel.Application")

Open in new window

You can also test if Excel is open and first try Set xlApp = GetObject(, "Excel.Application") and only CreateObject if that is an error.
   'attempting to use something that is not available
   'will generate an error
   On Error Resume Next
   Set objXL = GetObject(, "Excel.Application")
   On Error GoTo Proc_Err 'line label for error code*
  
   'If objXL is defined, then we
   'already have a conversation
   If TypeName(objXL) = "Nothing" Then
      booLeaveOpen = False 'dimension this as boolean and test to see if you need to objXL.quit
      'Excel was not open -- create a new instance
      Set objXL = CreateObject("Excel.Application")
   End If

Open in new window


Once you switch this, objXL.Visible = True (or False) should work too.

Don't forget to save and close the workbook, release objWkb,  and quit and release objXL, in that order.

*error handling videos on EE:

1. basic error handling code for VBA (3:48)
http://www.experts-exchange.com/videos/1478/Excel-Error-Handling-Part-1-Basic-Concepts.html

2. Run and Fix Code Loop through rows of an Excel spreadsheet using VBA (6:00)
http://www.experts-exchange.com/videos/1498/Excel-Error-Handling-Part-2-VBA-to-Copy-Values-Down-to-Blank-Cells-in-an-Excel-Column.html

3. Error Handling Part 3 - Run and Fix Bugs (7:51)
http://www.experts-exchange.com/videos/1518/Excel-Error-Handling-Part-3-Run-and-Fix-Bugs.html
0
 

Author Closing Comment

by:LJKMartin
ID: 41799346
Thanks Crystal
0
 
LVL 21
ID: 41799912
you're welcome ~ happy to help
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

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…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

632 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