Accessing Excel from Access

J

Jonathan Blitz

I need to access Excel from within Access and to export the contents of an
Excel spreadsheet to a text file.
Anyone know how I do this?

--
Jonathan Blitz
AnyKey Limited
Israel

"When things seem bad
Don't worry and shout
Just count up the times
Things have worked themselves out."
 
K

Ken Snell

Why go through EXCEL? Use the TransferText operation in ACCESS and go
directly to the text file.
 
J

Jonathan Blitz

I have the data in Excel and I need to transfer it into a CSV file.
This is because using Access directly to fetch the data causes problems do
to the mixed contents of the data in a single column (numeric and
character).
If I out it in a CSV file then it is much easier to import it all as
character.

I need top do this without user intervention.

--
Jonathan Blitz
AnyKey Limited
Israel

"When things seem bad
Don't worry and shout
Just count up the times
Things have worked themselves out."
 
A

Alick [MSFT]

Hi Jonathan,

One possible way is to use automation, you can automate Excel and call its
native SaveAs method to save it as csv file. Below is a sample for your
reference:

Note: need to add Microsoft Excel object library reference.

Dim xlApp As Excel.Application
Dim Path As String

Path = "d:\escf.xls"

'Check to see if the file name passed in to
'the procedure is valid
If Dir(Path) = "" Then
MsgBox Path & " isn't a valid path!"
Exit Sub
Else
Set xlApp = CreateObject("Excel.Application")

'You do not need to make the application object visible
'if you close the file and quit the application
'later in your code in order to remove these objects
'from memory.

xlApp.Visible = False
xlApp.Workbooks.Open Path

xlApp.ActiveWorkbook.SaveAs "d:\ff.csv", xlCSV

xlApp.ActiveWorkbook.Close False

xlApp.Quit

End If

For more about automation, download the help file from the support site,
the link is in the article below.

OFF2000: Microsoft Office 2000 Automation Help File Available [of20]
http://support.microsoft.com/support/kb/articles/q260/4/10.asp

Please feel free to reply to the threads if you have any concerns or
questions.



Sincerely,

Alick Ye, MCSD
Product Support Services
Microsoft Corporation
Get Secure! - <www.microsoft.com/security>

This posting is provided "AS IS" with no warranties, and confers no rights.






--------------------
| From: "Jonathan Blitz" <[email protected]>
| References: <[email protected]>
<[email protected]>
| X-Tomcat-NG: microsoft.public.access.formscoding
|
| I have the data in Excel and I need to transfer it into a CSV file.
| This is because using Access directly to fetch the data causes problems do
| to the mixed contents of the data in a single column (numeric and
| character).
| If I out it in a CSV file then it is much easier to import it all as
| character.
|
| I need top do this without user intervention.
|
| --
| Jonathan Blitz
| AnyKey Limited
| Israel
|
| "When things seem bad
| Don't worry and shout
| Just count up the times
| Things have worked themselves out."
| | > Why go through EXCEL? Use the TransferText operation in ACCESS and go
| > directly to the text file.
| >
| > --
| > Ken Snell
| > <MS ACCESS MVP>
| >
| > | > > I need to access Excel from within Access and to export the contents
of
| an
| > > Excel spreadsheet to a text file.
| > > Anyone know how I do this?
| > >
| > > --
| > > Jonathan Blitz
| > > AnyKey Limited
| > > Israel
| > >
| > > "When things seem bad
| > > Don't worry and shout
| > > Just count up the times
| > > Things have worked themselves out."
| > >
| > >
| >
| >
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top