473,396 Members | 1,758 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,396 software developers and data experts.

Extracting Excel File items within Access via VBA


I need to extract information from some Excel files but am stuck with
part of it:

As an example, I have the following Excel File that has 3 tabbed
sheets:
FileName: C:\ExcelData\JulyFile1.xls
SheetName: Sheet1-07032007 RowCount: 325 ColumnCount: 15
SheetName: Sheet2-07102007 RowCount: 450 ColumnCount: 25
SheetName: Sheet3-07172007 RowCount: 625 ColumnCount: 45
(I have 7 other Excel files with similar attributes)

I have code to open an Excel object, but am having trouble extracting
some other items from these files.

In my Access app, I need to loop through a series of Excel Files in a
folder and need to retrieve the filename if it is indeed an .xls
filetype.
Within each file, I need to retrieve the names of the sheet tabs, as
well as the row count and column count and column names within each
sheet.

Does someone have a code sample of how these items can be extracted
from an Excel file via VBA?

Thanks....

Jul 11 '07 #1
6 4894
Look at the Transferspreadsheet function in the Help file for retrieving
data from Excel. Look at the Dir function in the Help file for getting file
names.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
re******@pcdatasheet.com


<rl*********@yahoo.comwrote in message
news:11*********************@22g2000hsm.googlegrou ps.com...
>
I need to extract information from some Excel files but am stuck with
part of it:

As an example, I have the following Excel File that has 3 tabbed
sheets:
FileName: C:\ExcelData\JulyFile1.xls
SheetName: Sheet1-07032007 RowCount: 325 ColumnCount: 15
SheetName: Sheet2-07102007 RowCount: 450 ColumnCount: 25
SheetName: Sheet3-07172007 RowCount: 625 ColumnCount: 45
(I have 7 other Excel files with similar attributes)

I have code to open an Excel object, but am having trouble extracting
some other items from these files.

In my Access app, I need to loop through a series of Excel Files in a
folder and need to retrieve the filename if it is indeed an .xls
filetype.
Within each file, I need to retrieve the names of the sheet tabs, as
well as the row count and column count and column names within each
sheet.

Does someone have a code sample of how these items can be extracted
from an Excel file via VBA?

Thanks....

Jul 11 '07 #2
"Steve" <so***@private.emailaddresswrote in message
news:mV*****************@newsread1.news.pas.earthl ink.net...
Look at the Transferspreadsheet function in the Help file for retrieving
data from Excel.
Absolute drivel. TransferSpreadsheet is a method and not a function but
won't do what the OP wants anyway. Please stop posting this kind of crap
just to get your sig line aired. On second thoughts, keep posting ... it
shows the whole community that you haven't a clue.

To the OP:

You need to declare the workbook and each sheet as objects then use code to
interrogate them. Here's a code extract from one of my apps which should
get you started.

Keith.
www.keithwilby.com

Sub test()

Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim objRange As Excel.Range

Set objXL = New Excel.Application
Set objWkb = objXL.Workbooks.Open("C:\ExcelData\JulyFile1.xls")
Set objWkb = objXL.ActiveWorkbook

objXL.Visible = False

Set objSht = objWkb.Sheets(1)
Debug.Print objSht.Name

Set objRange = objSht.Range("A1").CurrentRegion
Debug.Print objRange.Columns.Count

objXL.Quit
Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing

End Sub

Jul 12 '07 #3
Set objSht = objWkb.Sheets(1)
Debug.Print objSht.Name
Thank you Keith for your reply.

Is there a way to loop through an .xls file and get the qty and names
of all sheets contained therein?

Jul 13 '07 #4
<rl*********@yahoo.comwrote in message
news:11*********************@m3g2000hsh.googlegrou ps.com...
>Set objSht = objWkb.Sheets(1)
Debug.Print objSht.Name

Thank you Keith for your reply.

Is there a way to loop through an .xls file and get the qty and names
of all sheets contained therein?
Dim i As Integer
For i = 1 To objWkb.Sheets.Count
Debug.Print Sheets(i).Name
Next i

HTH - Keith.
www.keithwilby.com

Jul 16 '07 #5
On Jul 16, 2:15 am, "Keith Wilby" <h...@there.comwrote:
<rlntemp-...@yahoo.comwrote in message

news:11*********************@m3g2000hsh.googlegrou ps.com...
Set objSht = objWkb.Sheets(1)
Debug.Print objSht.Name
Thank you Keith for your reply.
Is there a way to loop through an .xls file and get the qty and names
of all sheets contained therein?

Dim i As Integer
For i = 1 To objWkb.Sheets.Count
Debug.Print Sheets(i).Name
Next i

HTH - Keith.www.keithwilby.com
This worked great, Keith, thank you for this quick response. I
appreciate your help here today.

Jul 17 '07 #6
<rl*********@yahoo.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...
>
This worked great, Keith, thank you for this quick response. I
appreciate your help here today.
No problem, glad to help.

Keith.

Jul 17 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike Knight | last post by:
(I've also posted this problem on microsoft.public.excel.programming) I have a MS Access 2003 Database named "AS400 Fields.mdb". This database contains links to tables on an AS400. In MS...
4
by: phong.lee | last post by:
Here is an issue i've been trying to figure out which i do not have an answer to. Basically i have an excel spreadsheet which has data that i copy and paste from another resource. I also created...
9
by: jillandgordon | last post by:
I am trying to import an excel file into Access 97. It looks perfectly all right but, every time I try to import it, I get to the lst step and am told that it was not imported due to an error. ...
8
by: Nick M | last post by:
Hello All, Excellent info here Thanks! I am very new to using access in general and I am on a learning curve. I'm trying to import an excel workbook (with worksheets) into an access db via a...
0
by: acharyaks | last post by:
Hi life saver, I am using excel component for the development. The purpose is to connect to excel through the odbc connection string. Then through the connection extract data into a dataset and...
1
by: Gerry | last post by:
I have an ASP.NET application installed on a Windows Server 2003 computer. MS Excel is also installed on the same computer. And yes, the application makes use of Excel. When the Application Pool...
0
by: Robbe Morris [C# MVP] | last post by:
We own a variety of components that work with Excel files in a web environment (of course we can't use Excel automation in a high traffic web environment). SpreadSheet Gear (great component),...
0
by: Sajit | last post by:
I am trying to use an Excel file as a template for an Access report. I Linked the Excel file through an unbound frame as an OLE object with the properties set as follows: Source Doc...
4
by: DeanL | last post by:
Hi guys, I'm fairly fluent in MS Access but I've been handed a task that is baffling me. I've been asked to produce a report(s) in Excel that has a series of sales by territory. I have a bunch...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.