Monoxide3009 wrote:It is not uncommon for my company to have multiple excel files open. With that in mind, my current script obtains the specific excel title needed and stores it as a variable using WinActivate, %EXCEL% to pull the appropriate one. Can I add the title into this somewhere?
Also - Is there a way to obtain the row that is currently selected as a variable? This is less necessary because I can just make that a manual input on the first iteration, and have the variable++ for consecutive, but the less manual input the better (and more awe inspiring to the brass)
Once you embrace COM, alot can be done with Excel very quickly and reliably.
Here is an example of a function that will get a handle to a workbook.
Code: [Select all] [Expand] [Download] (Untitled.ahk)GeSHi © Codebox Plus
xlWb1 := xlGet_Workbook("One.xlsx", A_Desktop "\Test\")
xlWb2 := xlGet_Workbook("Two.xlsx")
MsgBox % xlWb1.ActiveSheet.Range("A1").Value
MsgBox % xlWb2.Worksheets(2).Range("A1").Value
MsgBox % xlWb2.Worksheets("Test").Range("A2").Value
MsgBox % xlWb2.Worksheets("Test").Range("A2").Row
MsgBox % xlApp.ActiveCell.Address
MsgBox % xlApp.ActiveCell.Row
MsgBox % xlApp.ActiveWorkbook.Name
global xlApp ; once function is called xlApp will be available to use outside the function
If !Path ; default path
Path := A_Desktop "\Test\"
if !xlApp ; If no xlApp then attempt to connect to running app or open app
xlApp := ComObjActive("Excel.Application")
xlApp := ComObjCreate("Excel.Application")
xlApp.Visible := true
try ; try to connect to open workbook
xlWb := xlApp.Workbooks(WB)
try ; try to open workbook
xlWb := xlApp.Workbooks.Open(Path WB)
catch ; catch failure to open
MsgBox % "Wookbook: " WB "`nCannot be found at: " Path WB
This basically connects to a workbook, opening the workbook if needed. It has some error checking but if you attempt to access stuff that don't exist you will probably get an error. You would need to change all the names and paths to actually test this script to files that exist on your system.
It also shows some basic other things like how to reference specific sheets and how to find out information about the active cell or workbook.
And if you really want to be fancy all of this could be done in the background without ever displaying or appearing to open Excel. You can access everything about an Excel workbook completely invisibly.