473,770 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(C ells(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 2258
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(C ells(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(X Lsheet.Cells(4, 1), _
XLsheet.Cells(X Lrows + 3, XLcols))

in stead of

SAVarray()= XLsheet.Range(C ells(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(C ells(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(X Lsheet.Cells(4, 1), _
XLsheet.Cells(X Lrows + 3, XLcols))

in stead of

SAVarray()= XLsheet.Range(C ells(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.microso ft.com/default.aspx?kb id=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
17418
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 a database for her which is intended to make things a lot easier; however, I don't have a lot of experience with Access and I find that designing the reports in Access is tedious. I want to be able to print the reports (which are simply based on...
2
9497
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 Export to Excel Link then I have a button which returns the user to a form view. It's a 3 step process with the user needing to Save As in Excel if they wish to keep the spreadsheet. Are there any other easier options? It seems I should be able...
7
5340
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 able to destroy instances of excel (with the exact same code). I have read many, many posts, and they seem to get bogged down in specifics. So I cribbed this program from the automation help file, simplified it further, so hopefully someone can
1
3604
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 task manager and I'm unable to open the spreadsheet without first closing down Access. Can anyone help!? Dave Public Function CreateInputSheet(scriptName As String, ParamArray
9
4437
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 asp.net. The Xl sheet should not be opened in the browser. All the information from dataset(datatable,datarows) should be sent to XL and the file name should be given dynamically through program and the xl file should be saved dynamically through...
0
973
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
801
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 automation breaks on those machines. Does coding to the earliest supported version of Excel not apply once you get to 2003?
1
1709
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 automation breaks on those machines. Does coding to the earliest supported version of Excel not apply once you get to 2003?
4
2764
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 line graph be created from Access as part of the automation process? Is it also possible to rename the Excel worksheets from Access? Thanks. Keith.
12
3809
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
9602
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10237
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9882
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7431
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3987
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
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.