dbTalk Databases Forums  

A2K- automating Excel for a simple couple of tasks

comp.databases.ms-access comp.databases.ms-access


Discuss A2K- automating Excel for a simple couple of tasks in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
buckskin
 
Posts: n/a

Default A2K- automating Excel for a simple couple of tasks - 02-07-2011 , 08:04 AM






Maybe my google searches are utterly rubbish but I need to filter out the
code one would use to open a specified Excel file from within Access, save
it to the latest Excel format (NOT xlsx), check if the top row is empty (if
so delete that row and save), then finally close the file.

Is this a few lines of code or a bit more complicated?

thanks
Martin
- am feeling a bit stupid today...

Reply With Quote
  #2  
Old   
The Frog
 
Posts: n/a

Default Re: A2K- automating Excel for a simple couple of tasks - 02-08-2011 , 01:43 AM






Hi Martin,

Automating Excel is pretty simple. Most of what you want to do is most
easily achieved by first recording a macro in Excel to do the things
that you want to handle internally to the document, then simply copy /
paste that code across into Access for use in your automation routine.

To get Excel up and running for example is easy:
Dim xl as Excel.Application
You need to set a reference to Excel in Tools>References for that to
work. This becomes your copy of Excel to play with. If you want to
check a large number of cells for the existance of values you are
probably better to collect the entire worksheet you want into an array
and check that by looping through the elements, as looping through
Excels cells is quite slow:
Dim x as Variant
Dim ws as xl.Worksheet
set ws = xl.ActiveWorkbook.Sheets(1) 'You can also use a sheetname
in quotes
x = ws.range("A1:IV65536")

What you end up with here is a two dimensional array in R1C1 format
(ie/ 1,1 is the first cell). To capture this takes only a fraction of
a second, and looping through each cell of the first row maybe another
fraction of a second in total.

Dont forget to clean up the objects you create as they can end up
using some decent amounts of memory if left running. Also, when you
instantiate your application object for Excel it doesnt have to be
visible to the user either. If you get stuck just open a new workbook
in Excel, start recording a macro, then open the workbook you want to
work on and do your things, save the way you want to and close the
workbook; now stop your macro and paste the code here - maybe we can
help.

Cheers

The Frog

Reply With Quote
  #3  
Old   
buckskin
 
Posts: n/a

Default Re: A2K- automating Excel for a simple couple of tasks - 02-09-2011 , 06:10 AM



"The Frog" <mr.frog.to.you (AT) googlemail (DOT) com> wrote

Quote:
Hi Martin,

Automating Excel is pretty simple. Most of what you want to do is most
easily achieved by first recording a macro in Excel to do the things
that you want to handle internally to the document, then simply copy /
paste that code across into Access for use in your automation routine.

Thanks dude, that's useful and I shall make a start from there!

thanks again.

Reply With Quote
  #4  
Old   
The Frog
 
Posts: n/a

Default Re: A2K- automating Excel for a simple couple of tasks - 02-10-2011 , 04:08 AM



Anytime. Drop a note in this thread if you need help.

Cheers

The Frog

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.