Jump to content

[Newbie] Excel Read selected row & column


s3nsei
 Share

Recommended Posts

Hello guys,

Please kindly help me, is there any way to read the selected row & column in Excel?

I'm trying to format the font of selected cell in Excel, below is my noob script :

===START===

#include <Excel.au3>

#include <File.au3>

Opt("WinTitleMatchMode", 2)

$sFilePath = @DesktopDir & "\test.xls"

$Excel = "test"

$oExcel = _ExcelBookAttach($sFilePath)

WinActivate($Excel)

_ExcelWriteCell($oExcel, "TEST", 1, 1)

$Row = $oExcel.activesheet.row

$Column = $oExcel.activesheet.column

_ExcelFontSetProperties($oExcel,$Row , $Column, $Row, $Column, True, True, True)

===END===

My script is a totally disaster, if anyone know the answer, please kindly tell me.

Thanks a lot. ;)

Link to comment
Share on other sites

;===START===
#include <Excel.au3>
#include <File.au3>
Opt("WinTitleMatchMode", 2)
$sFilePath = @DesktopDir & "\test.xls"; no need to duplicate all is in here
$oExcel = _ExcelBookOpen($sFilePath, 1) ; 1= Visable 0 = Not Visable

;=== Testing to see if the file exist as per help file
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
;=== Done the testing bit
_ExcelSheetActivate($oExcel, "sheet1") ; Open correct sheet

WinActivate($oExcel)
_ExcelWriteCell($oExcel, "TEST", 1, 1) ; The same as cell A1

$sRangeOrRowStart = 1 ; Can use as A1:A2 spesifing a range else it is seen as the first row number and the rest needs to be used ==>>
$iColStart = 1
$iRowEnd = 1
$iColEnd = 1
$fBold = True
$fItalic = True
$fUnderline = True

_ExcelFontSetProperties($oExcel, $sRangeOrRowStart, $iColStart, $iRowEnd, $iColEnd, $fBold, $fItalic, $fUnderline )
sleep(2000)
_ExcelBookClose($oExcel, 1, 0); 1 = Save before closing
;===END===
Hi

Here is a working script to start off with:

Edited by JoHanatCent
Link to comment
Share on other sites

Dear all,

Thank you so much for your answer and attention, love you all.. ;)

Now, i'm wondering where'd you get below underlined parameter ?

$oExcel.Application.Selection.Address(False, False)

Any link / reference is much appreciated.

Thanks a lot :)

Link to comment
Share on other sites

Dear all,

Thank you so much for your answer and attention, love you all.. :)

Now, i'm wondering where'd you get below underlined parameter ?

$oExcel.Application.Selection.Address(False, False)

Any link / reference is much appreciated.

Thanks a lot :shocked:

Google + MSDN site ;)

Application = http://msdn.microsoft.com/en-us/library/bb210077(v=office.12).aspx

"Represents the entire Microsoft Excel application."

Selection = http://msdn.microsoft.com/en-us/library/bb214188(v=office.12).aspx

Application's property.

Address = http://msdn.microsoft.com/en-us/library/bb213510(v=office.12).aspx

Range's property.

MSDN site is a good referente for Microsoft's softwares. You can play around with some good stuffs from there.

;)

Edited by SeF
Link to comment
Share on other sites

Good day all,

Does anyone have any idea how to fix below error? Please kindly assist, thanks a lot!

ERROR MESSAGE :

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\jkt-willyl\My Documents\Autoit\Share\LOG.au3"

C:\Program Files\AutoIt3\Include\Excel.au3 (410) : ==> The requested action with this object has failed.:

$oExcel.Application.DisplayAlerts = $fDisplayAlerts

$oExcel.Application^ ERROR

>Exit code: 1 Time: 1060.214

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...