473,408 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Opening Excel file from Access

4
Hello,

I have about 200 records in an Access database that each have a corresponding Excel file attached to it. I have this code

Expand|Select|Wrap|Line Numbers
  1. Set xlApp = New Excel.Application
  2.     With xlApp
  3.         .Visible = True
  4.         Set xlWB = .Workbooks.Open("C:\Documents and Settings\All Users\" & Text167, , False)
  5.         With xlWB.Sheets("Sheet1")
  6. End With
  7. End With
  8.  
Text167 is the textbox in Access that contains the filename for each specific record. The filenames are always in the format "name - year". So an example would be "ABC - 2005".

That code opens the Excel files perfectly EXCEPT when the filename has a period in it. Whether it's a period at the end or in the middle of the filename it won't open the file. So if it's "A.BC - 2005" or "ABC. - 2005" it won't open the file. It says the file doesn't exist.

Is there something I'm not seeing in the code?
Mar 1 '07 #1
5 2490
MMcCarthy
14,534 Expert Mod 8TB
Hello,

I have about 200 records in an Access database that each have a corresponding Excel file attached to it. I have this code

Expand|Select|Wrap|Line Numbers
  1. Set xlApp = New Excel.Application
  2.     With xlApp
  3.         .Visible = True
  4.         Set xlWB = .Workbooks.Open("C:\Documents and Settings\All Users\" & Text167, , False)
  5.         With xlWB.Sheets("Sheet1")
  6. End With
  7. End With
  8.  
Text167 is the textbox in Access that contains the filename for each specific record. The filenames are always in the format "name - year". So an example would be "ABC - 2005".

That code opens the Excel files perfectly EXCEPT when the filename has a period in it. Whether it's a period at the end or in the middle of the filename it won't open the file. So if it's "A.BC - 2005" or "ABC. - 2005" it won't open the file. It says the file doesn't exist.

Is there something I'm not seeing in the code?
It won't see the period as valid in the name. It will assume it's followed by a file extension. You will have to rename the files.

Mary
Mar 1 '07 #2
aran
4
It won't see the period as valid in the name. It will assume it's followed by a file extension. You will have to rename the files.

Mary
Thank you.

So this is more of a limitation of Windows rather than Access or VBA?
Mar 1 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Thank you.

So this is more of a limitation of Windows rather than Access or VBA?
Yes, it is I'm afraid.
Mar 1 '07 #4
aran
4
For anyone curious, I've found a solution for this:

Expand|Select|Wrap|Line Numbers
  1. Set xlApp = New Excel.Application
  2.         With xlApp
  3.             .Visible = True
  4.             Set xlWB = .Workbooks.Open("C:\Documents and Settings\All Users\" & Text167 & ".xls", , False)
  5. End With
  6. End With
  7.  
All I had to do was add the file extension at the end.
Mar 2 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
For anyone curious, I've found a solution for this:

Expand|Select|Wrap|Line Numbers
  1. Set xlApp = New Excel.Application
  2.         With xlApp
  3.             .Visible = True
  4.             Set xlWB = .Workbooks.Open("C:\Documents and Settings\All Users\" & Text167 & ".xls", , False)
  5. End With
  6. End With
  7.  
All I had to do was add the file extension at the end.
Thanks for posting the solution aran.

Mary
Mar 2 '07 #6

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

Similar topics

4
by: Vishal | last post by:
Hello, I have a dataset with some content. I can convert this dataset in a csv format which is then stored in a stringwriter. Now I want this be open via excel, so I set the contenttype...
4
by: Josh Behl | last post by:
When I try to programmatically open an existing Excel document using a custom windows form, it works perfectly. I instanciate a new instance of the Excel.ApplicationClass and then set the Visible...
3
by: Donald Grove | last post by:
I need to get data from a table in .dbf format. I try importing it, but get "external table not in expected format". So I tried this VB code to see if I could get at my records with ADO (which...
2
by: Riddle | last post by:
Hi, I have found many tutorials showing how to access data in an Excel spreadsheet using a COM object in .net. But, as far as I can tell, this requires Excel to be installed. Is there anyway I...
1
by: meditcakepbgt | last post by:
halo i ve got another question.. in opening an excel file one of the important thing is getting to get the excel file which contain the most recent updates of the data. what is the code to...
2
by: Mad Scientist Jr | last post by:
>From an asp.net web page I want the user to open the results of a SQL query in Excel, as automatically as possible (ie not having to loop through columns, rows, in code). For this,...
0
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...
1
by: T | last post by:
Currently there is an excel shortcut available on the network with links to 30 or so access db (97 & 2003), since the users are complaining about all the messages from excel (already open, do you...
16
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.