Jump to content
Sign in to follow this  
andy09

Problem with excel functions and controls

Recommended Posts

andy09

Hi,

I would like to automate the following:

1)Open excel file "test.xls"

2)Copy a column from that file

3) Check if the excel file "apa.xls" is open. If yes, activate it, if no open it

4) Paste the data into a new row

5) Close excel file "test.xls"

I've succeded with 1) and 2) and 4) but I need help with something for no 3)

I've used _ExcelBookOpen but it just opens a new copy of the excel file each time I call it.

This is the code so far:

CODE
#include <Array.au3>

#include <Excel.au3>

$sFilePath1 = "C:\Test.xls"

$oExcel = _ExcelBookOpen($sFilePath1)

If @error = 1 Then

MsgBox(0, "Error!", "Unable to Create the Excel Object")

Exit

ElseIf @error = 2 Then

MsgBox(0, "Error!", "File does not exist - Shame on you!")

Exit

EndIf

$aArray1 = _ExcelReadArray($oExcel, 2, 4, 70, 1) ;Direction is Vertical

;the following just opens up a new copy of apa.xls each time... Could Excelsheetactivate work? how? other ideas?

$sFilePath2 = "C:\apa.xls" ;This file should already exist

$oExcel2 = _ExcelBookOpen($sFilePath2)

_ExcelWriteArray($oExcel2, 1, 1, $aArray1)

Share this post


Link to post
Share on other sites
PsaltyDS

Hi,

I would like to automate the following:

1)Open excel file "test.xls"

2)Copy a column from that file

3) Check if the excel file "apa.xls" is open. If yes, activate it, if no open it

4) Paste the data into a new row

5) Close excel file "test.xls"

I've succeded with 1) and 2) and 4) but I need help with something for no 3)

I've used _ExcelBookOpen but it just opens a new copy of the excel file each time I call it.

This is the code so far:

CODE
#include <Array.au3>

#include <Excel.au3>

$sFilePath1 = "C:\Test.xls"

$oExcel = _ExcelBookOpen($sFilePath1)

If @error = 1 Then

MsgBox(0, "Error!", "Unable to Create the Excel Object")

Exit

ElseIf @error = 2 Then

MsgBox(0, "Error!", "File does not exist - Shame on you!")

Exit

EndIf

$aArray1 = _ExcelReadArray($oExcel, 2, 4, 70, 1) ;Direction is Vertical

;the following just opens up a new copy of apa.xls each time... Could Excelsheetactivate work? how? other ideas?

$sFilePath2 = "C:\apa.xls" ;This file should already exist

$oExcel2 = _ExcelBookOpen($sFilePath2)

_ExcelWriteArray($oExcel2, 1, 1, $aArray1)

3) _ExcelBookAttach()

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.