Jump to content

Problem with excel functions and controls


andy09
 Share

Recommended Posts

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)

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...