i have done some changes, all work on xppro sp2 and office 2003
excel.com.ahk:
add some method:
- Excel_SetSheet(sheet) : active a sheet (getcell and settext are used on active sheet
- Excel_GetSheet() : get active sheet
- Excel_CheckSheet(thisSheet) : check if a sheet exist, but need
- Excel_AddSheet(position, name) : add to position a sheet (sheetX if name is null)
- Excel_RenameSheet(X,name) : rename sheet(X) to name
- Excel_MoveSheet(pos,sheet1,sheet2) : pos = "B"(efore) or "A"(fter), sheet1 is moved before/after sheet2
Code:
; **************************************************************************
; Author: BENJAMIN
; Language: AutoHotkey v1.0.47.06
; Creation Date: 02/04/2009 16:55
; Function Name: Excel_SetSheet(sheet) / Excel_GetSheet()
;
;Get or Set the working sheet used
;
; Syntax:
; Excel_SetSheet(sheet) / Excel_GetSheet()
; Parameters:
; thisSheet
; Return:
; Success =
; Failure =
; **************************************************************************
Excel_SetSheet(thisSheet){
global
if !oExcel := COM_GetActiveObject("Excel.Application") { ; Get the Already Running Instance
MsgBox Could not find Excel Instance.
Return
}
sheet := thisSheet
oWorkbook := COM_Invoke(oExcel,"ActiveWorkbook")
ws := COM_Invoke(oWorkbook, "Worksheets",sheet)
COM_Invoke(ws, "activate")
}
Excel_GetSheet(){
global
return sheet
}
Excel_CheckSheet(thisSheet){
if !oExcel := COM_GetActiveObject("Excel.Application") { ; Get the Already Running Instance
MsgBox Could not find Excel Instance.
Return
}
test := thisSheet
oWorkbook := COM_Invoke(oExcel,"ActiveWorkbook")
if COM_Invoke(oWorkbook, "Worksheets",test)
return 1
else
return 0
}
; **************************************************************************
; Author: BENJAMIN
; Language: AutoHotkey v1.0.47.06
; Creation Date: 02/04/2009 16:55
; Function Name: Excel_AddSheet()
;
; Add a sheet in first position with name sheetX
;
; Syntax:
; Excel_AddSheet()
; Parameters:
; thisSheet
; Return:
; Success =
; Failure =
; **************************************************************************
Excel_AddSheet(thispos, name=""){
if !oExcel := COM_GetActiveObject("Excel.Application") { ; Get the Already Running Instance
MsgBox Could not find Excel Instance.
Return
}
oWorkbook := COM_Invoke(oExcel,"ActiveWorkbook")
oWorksheets := COM_Invoke(oWorkbook, "Worksheets")
pos := thispos
Excel_SetSheet(pos)
oWorksheet := COM_Invoke(oWorksheets,"Add")
ifNotEqual,name,
COM_Invoke(oWorksheet, "Name",name)
}
;position = B (before) or A(after)
Excel_MoveSheet(position,thisSheet,thisSheet2){
global
if !oExcel := COM_GetActiveObject("Excel.Application") { ; Get the Already Running Instance
MsgBox Could not find Excel Instance.
Return
}
sheet = Sheets[%thisSheet%].Move
sheet2 := thisSheet2
oWorkbook := COM_Invoke(oExcel,"ActiveWorkbook")
ws2 := COM_Invoke(oWorkbook, "Sheets",sheet2)
ifEqual,position,B
COM_Invoke(oWorkbook, sheet,"+" ws2)
else
COM_Invoke(oWorkbook, sheet,"-0", "+" ws2)
}
Excel_RenameSheet(thisSheet,name){
global
if !oExcel := COM_GetActiveObject("Excel.Application") { ; Get the Already Running Instance
MsgBox Could not find Excel Instance.
Return
}
sheet := thisSheet
oWorkbook := COM_Invoke(oExcel,"ActiveWorkbook")
ws := COM_Invoke(oWorkbook, "Worksheets",sheet)
COM_Invoke(ws, "Name",name)
}