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

excel automation thru access- array/implicit ref problem

I'm working on a program that imports a bunch of data from a folder
full of Excel files and compiles it into an Access DB. The Excel files
have a varying number of rows and columns that need to be imported,
and the data needs to be processed/error checked before it's written
to the DB. The way I've tackled this is to have a procedure that steps
through a list of Excel files, invokes an instance of Excel, opens
file "x", copies the relevant data to an array, then closes the xls
file and the Excel application. The data gets processed in the array,
then once it's in a format amenable to Access, it gets written to the
DB. Move on to the next .xls file; rinse and repeat. Simple.

The trouble I'm encountering appears to be the dreaded "implicit
reference". The Excel application fails to close if I use the
following:

'SAVarray() is a variant array
'XLrows and XLcols are the dimensions of the dataset, they've been
previously mapped

SAVarray()= XLsheet.Range(Cells(4, 1), Cells(XLrows + 3, XLcols))
'relevant data starts in row 4, column 1

<do something with the array here...>

redim SAVarray(1) ' since I'm done with the data, I want to erase the
array here

set XLsheet = nothing

This obviously omits a lot of pre- and post- coding, but this is the
section that causes the trouble, so the rest is fairly unimportant.

If I replace the above with the following, Excel behaves nicely:

ReDim SAVarray(1 To XLrows, 1 To XLcols) 'base 1 array
i = 1

Do Until i = XLrows + 1
j = 1
Do Until j = XLcols + 1
SAVarray(i, j) = XLsheet.Cells(i + 3, j).Value
j = j + 1
Loop
i = i + 1
Loop

<do something with the array here...>

redim SAVarray(1) ' since I'm done with the data, I want to erase the
array here

set XLsheet = nothing

The trouble is, this is sloooooooooow. Putting the whole range into
the array in one step is much, much faster. My guess is that when you
use the range to fill the array, it makes Access think that SAVarray()
is an Excel widget(??). Any thoughts on syntax that might make this
work? Thanks in advance; I hope I'm not missing something really
obvious.

Greg

Aug 13 '07 #1
2 2229
ge******@yahoo.com wrote:
I'm working on a program that imports a bunch of data from a folder
full of Excel files and compiles it into an Access DB. The Excel files
have a varying number of rows and columns that need to be imported,
and the data needs to be processed/error checked before it's written
to the DB. The way I've tackled this is to have a procedure that steps
through a list of Excel files, invokes an instance of Excel, opens
file "x", copies the relevant data to an array, then closes the xls
file and the Excel application. The data gets processed in the array,
then once it's in a format amenable to Access, it gets written to the
DB. Move on to the next .xls file; rinse and repeat. Simple.

The trouble I'm encountering appears to be the dreaded "implicit
reference". The Excel application fails to close if I use the
following:

'SAVarray() is a variant array
'XLrows and XLcols are the dimensions of the dataset, they've been
previously mapped

SAVarray()= XLsheet.Range(Cells(4, 1), Cells(XLrows + 3, XLcols))
'relevant data starts in row 4, column 1

<do something with the array here...>

redim SAVarray(1) ' since I'm done with the data, I want to erase the
array here

set XLsheet = nothing

This obviously omits a lot of pre- and post- coding, but this is the
section that causes the trouble, so the rest is fairly unimportant.

If I replace the above with the following, Excel behaves nicely:

ReDim SAVarray(1 To XLrows, 1 To XLcols) 'base 1 array
i = 1

Do Until i = XLrows + 1
j = 1
Do Until j = XLcols + 1
SAVarray(i, j) = XLsheet.Cells(i + 3, j).Value
j = j + 1
Loop
i = i + 1
Loop

<do something with the array here...>

redim SAVarray(1) ' since I'm done with the data, I want to erase the
array here

set XLsheet = nothing

The trouble is, this is sloooooooooow. Putting the whole range into
the array in one step is much, much faster. My guess is that when you
use the range to fill the array, it makes Access think that SAVarray()
is an Excel widget(??). Any thoughts on syntax that might make this
work? Thanks in advance; I hope I'm not missing something really
obvious.

Greg
Did you try

SAVarray()= _
XLsheet.Range(XLsheet.Cells(4, 1), _
XLsheet.Cells(XLrows + 3, XLcols))

in stead of

SAVarray()= XLsheet.Range(Cells(4, 1), Cells(XLrows + 3, XLcols))

Your syntax (without "anchoring" the Cells object to it's parent
object, might cause what you're experiencing. Check out
http://support.microsoft.com/default.aspx?kbid=178510
for more info

--
Roy-Vidar
Aug 13 '07 #2
Thanks a bunch... that looks like it.

Greg

On Aug 13, 5:03 pm, RoyVidar <roy_vidarNOS...@yahoo.nowrote:
gelli...@yahoo.com wrote:
I'm working on a program that imports a bunch of data from a folder
full of Excel files and compiles it into an Access DB. The Excel files
have a varying number of rows and columns that need to be imported,
and the data needs to be processed/error checked before it's written
to the DB. The way I've tackled this is to have a procedure that steps
through a list of Excel files, invokes an instance of Excel, opens
file "x", copies the relevant data to an array, then closes the xls
file and the Excel application. The data gets processed in the array,
then once it's in a format amenable to Access, it gets written to the
DB. Move on to the next .xls file; rinse and repeat. Simple.
The trouble I'm encountering appears to be the dreaded "implicit
reference". The Excel application fails to close if I use the
following:
'SAVarray() is a variant array
'XLrows and XLcols are the dimensions of the dataset, they've been
previously mapped
SAVarray()= XLsheet.Range(Cells(4, 1), Cells(XLrows + 3, XLcols))
'relevant data starts in row 4, column 1
<do something with the array here...>
redim SAVarray(1) ' since I'm done with the data, I want to erase the
array here
set XLsheet = nothing
This obviously omits a lot of pre- and post- coding, but this is the
section that causes the trouble, so the rest is fairly unimportant.
If I replace the above with the following, Excel behaves nicely:
ReDim SAVarray(1 To XLrows, 1 To XLcols) 'base 1 array
i = 1
Do Until i = XLrows + 1
j = 1
Do Until j = XLcols + 1
SAVarray(i, j) = XLsheet.Cells(i + 3, j).Value
j = j + 1
Loop
i = i + 1
Loop
<do something with the array here...>
redim SAVarray(1) ' since I'm done with the data, I want to erase the
array here
set XLsheet = nothing
The trouble is, this is sloooooooooow. Putting the whole range into
the array in one step is much, much faster. My guess is that when you
use the range to fill the array, it makes Access think that SAVarray()
is an Excel widget(??). Any thoughts on syntax that might make this
work? Thanks in advance; I hope I'm not missing something really
obvious.
Greg

Did you try

SAVarray()= _
XLsheet.Range(XLsheet.Cells(4, 1), _
XLsheet.Cells(XLrows + 3, XLcols))

in stead of

SAVarray()= XLsheet.Range(Cells(4, 1), Cells(XLrows + 3, XLcols))

Your syntax (without "anchoring" the Cells object to it's parent
object, might cause what you're experiencing. Check outhttp://support.microsoft.com/default.aspx?kbid=178510
for more info

--
Roy-Vidar

Aug 13 '07 #3

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

Similar topics

1
by: Steven Stewart | last post by:
I have a user who has been using Excel for a while to keep statistics and print reports. She finds using it cumbersome because of long formulas and a lot of copying and pasting. I have designed...
2
by: jeffgeorge | last post by:
I'm currently exporting a form to Excel. Because there are controls and totals in the header, I first have a button for users to convert to a datasheet. Then I use the automated quick office...
7
by: taylor.bryant | last post by:
I am running: Win XP SP2 Excel 2002, Access 2002 (Office XP SP3) Using Visual Basic (not VB.NET) At one point (prior to XP SP2?!? - I can't pin it down), this did not happen and I was easily...
1
by: u7djo | last post by:
Hi, I'm currently building a function in Access that creates an Excel spreadsheet but it doesn't look like the Excel object is being destroyed correctly as the Excel module is still showing in the...
9
by: hari krishna | last post by:
hi, I want to send the data from dataset information to Excel through ASP.Net. there will be no XL installed on web server. web server is win 2000 server machine. I am using visual basic code in...
0
by: Dickson | last post by:
How can I refresh excel workbook which I open it thru automation in Vb.Net. I need to refresh the excel workbook I open thru automation every 5 minutes. Any suggestion? Thanks.
0
by: Troy | last post by:
I have VB.Net code that opens Excel files and imports data from them. It works fine for all versions up to 2003 and has for over a year. We have users updating to Office 2003 and the Excel...
1
by: Troy | last post by:
I have VB.Net code that opens Excel files and imports data from them. It works fine for all versions up to 2003 and has for over a year. We have users updating to Office 2003 and the Excel...
4
by: Keith Wilby | last post by:
How controllable from Access VBA is Excel? I'm currently using automation to dump 2 columns of data into an Excel spreadsheet so that the end user can create a line graph based on it. Could the...
12
by: slinky | last post by:
Can an Excel spreadsheet or a section of one be embedded into an Access form and serve as a subform from which other parts of the Access form can get data? Thanks!
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.