473,516 Members | 2,889 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Opening Excel file from Access VBA not working

43 New Member
Hey all,

I am having issues when trying to open an Excel file from Access VBA. Here's the code I have so far:

Expand|Select|Wrap|Line Numbers
  1. Public Sub Prod()
  2.  
  3. Dim xlApp As Object
  4. Dim xlWorkbook As Object
  5. Dim strProd As String
  6.  
  7. 'Prepare Staff list
  8. Set dbs = CurrentDb()
  9. DoCmd.SetWarnings False
  10. strProd = "C:\Docs\Hours.xlsm"
  11. Set objrst = dbs.OpenRecordset("Report Date")
  12.  
  13. Set xlApp = CreateObject("Excel.Application")
  14.  
  15. With xlApp
  16.     .Visible = True
  17.     .DisplayAlerts = True
  18.     .CutCopyMode = False
  19.     Set xlWorkbook = Workbooks.Open(strProd)
  20.         xlWorkbook.Activate
  21.         Set xlSheet = xlWorkbook.Worksheets("VTO")
  22.         xlSheet.Activate
  23.         xlSheet.Range("D2").CopyFromRecordset objrst
  24.     .Run "Combine"
  25.     xlWorkbook.Save
  26.     xlWorkbook.Close
  27.     .DisplayAlerts = True
  28.     .Quit
  29. End With
  30.  
  31. End Sub
When I step into the code and I get to the lines that say:

Expand|Select|Wrap|Line Numbers
  1. Set xlWorkbook = Workbooks.Open(strProd)
  2.         xlWorkbook.Activate
The code will open the Excel application, but the workbook is not physically opening for some reason, so thus it won't run the "Combine" macro. Then when I get the error, it's telling me that the workbook is open but is not visible. Hopefully this makes sense. I'm sure it's something small, but my brain hurts trying to figure it out.

Thanks!
Apr 16 '13 #1
2 3758
ADezii
8,834 Recognized Expert Expert
It appears as though you need the Qualifier "." between the Application (xlApp) and the Collection (Workbooks), namely:
Expand|Select|Wrap|Line Numbers
  1.  Set xlWorkbook = .Workbooks.Open(strProd)
Apr 17 '13 #2
Lynch225
43 New Member
Wow, something as simple as a period. Worked perfectly, thanks!
Apr 17 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4975
by: Lisa | last post by:
I have an excel file on my server, which contains an embedded query. I want to be able to open the excel file, pass the contents of my variable into a cell within the worksheet and then refresh the query based on the variable passed. I can get the query part to work. The bit I can't get to work is where I open the excel file and pass the...
4
2069
by: Mark | last post by:
Hello - I receive the error message: System.Runtime.InteropServices.COMException: The remote procedure call failed. when I open an Excel file using from an ASP.Net page. Imports Microsoft.Office.Interop Imports System.Runtime.InteropServices.Marshal Public Sub LoadData()
3
1755
by: nagen | last post by:
i have an excel file stored in C:\Test.xls(server driver) i would like my web application to allow this file to be opened by the client by prompting the save as dialog..how can i do this in C#
2
4602
by: PJ6 | last post by:
This little snippet works for .txt files, but for any .xls file I get a file not found error, even though the file is really there. Yes, I checked to see if the path is correct, and yes, I have Excel installed. Any ideas what's going on? If I can't use Shell to get Excel to open a file, what do I use? TIA,
5
2494
by: aran | last post by:
Hello, I have about 200 records in an Access database that each have a corresponding Excel file attached to it. I have this code Set xlApp = New Excel.Application With xlApp .Visible = True Set xlWB = .Workbooks.Open("C:\Documents and Settings\All Users\" & Text167, , False) With xlWB.Sheets("Sheet1")
0
2105
by: peejay750 | last post by:
I have an Access application that needs to open an Excel workbook which has Cognos links in it. When I open the Excel workbook with the Cognos links in it using Excel, the Cognos Analyst menu is there. However, when I open the Excel workbook from Access VBA by creating an instance of Excel using Set objXL = CreateObject("Excel.Application")...
0
1255
by: jh8026 | last post by:
My problem seems to be regarding permissions, but I'm not sure why. I am developing an asp.net web application that needs to pull and display information from an excel file located on a server that is not the web server. I have set up "Windows" authentication in my web.config file and have set impersonate="true". Everything works fine when I...
3
6764
by: blerina | last post by:
hi, i have a simple asp code that opens an excel file. it works fine with simple excel files that don't contain formula. i think the problem is that my excel file contains formulas and calculations. when opening this file with vb 6.0 code it works fine. here is a the simple code: Dim xlObject, xlBook,wks
0
1033
by: veer | last post by:
hello expert i want to open excel files with common dialog box in vb . can i open it with DAO If no then please send me some idea so that i can open any excel file on my lan network thanks
16
5154
by: Phil Stanton | last post by:
I have a form with a button which is supposed to open an Excel file (With lots of Macros /VBA) in it. The Excel file gets it's data from the Access program Here is the code Private Sub Storage_Click() On Error GoTo Err_Storage_Click
0
7276
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7581
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7548
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5714
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4773
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
1624
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.