Blue_Drache Posted July 11, 2007 Share Posted July 11, 2007 Hi! It's me again. Here's the situation: I've written a program that prints out a number of individual items from a spreadsheet list. It works great! Peachy! Perfect.... EXCEPT... (yeah, always one of those) when there's more than one XL window open, and the XL window with the list wasn't the FIRST one opened. I thought I could make something to force the selection of the correct window, but I guess I'm doing it wrong... What I want to have happen is to be able to grab the object associated with the window the user selects in my GUI. Simply put, can what I propose be done with the current tools, or have I just wasted time in making something more complex than what it needs to be? expandcollapse popupOpt("MustDeclareVars", 1) Opt("PixelCoordMode", 0) #include <ExcelCOM_UDF.au3> #include <GUIConstants.au3> Dim $prevclip = ClipGet(), $dcn, $test1, $test2, $ans, $previousDCN = "123456789012x", $pass = 0, $oExcel, $Paused = 0 Dim $pxlChkSum, $temp, $counter = 0, $intLoop = 0, $oExcel Dim $aDates, $DateFlag, $hwndXL, $err $aDates = _DataDates($aDates) #region Primary Data Loop $hwndXL = _guiXLChoice() $err = @error Switch $err Case 1 MsgBox(0, "", "No Excel windows detected") Exit Case 2 MsgBox(0, "", "User pressed cancel, hit escape or X-ed out of window") Exit Case Else ; do nothing for now EndSwitch While 1 ; Get the DCN from the user $dcn = "" Do $pass = 0 If WinExists($hwndXL) Then WinActivate($hwndXL) ; change this to the handle variable detected from _XLDetect WinWaitActive($hwndXL, "", 60); change this to the handle variable detected from _XLDetect $oExcel = ObjGet("", "Excel.Application") ; sets the current Excel window as an object. $dcn = $oExcel.ActiveCell.Text ; grab the data from the current active cell. ;. ;. ;. Func _guiXLChoice() Local $aXLWindows = _XLDetect() If @error Then SetError(1) Return "" EndIf Local $intLoop, $intCount, $gui_MSG Local $gui_XLChoice = GUICreate($version, 350, 100 + (18 * $aXLWindows[0][0]), 50, 50) Local $rad_XL[$aXLWindows[0][0] + 1] $rad_XL[0] = $aXLWindows[0][0] GUICtrlCreateGroup("Detected Excel Windows", 5, 5, 340, 60 + (18 * $aXLWindows[0][0])) For $intLoop = 1 To $rad_XL[0] $rad_XL[$intLoop] = GUICtrlCreateRadio($aXLWindows[$intLoop][0], 25, 5 + (20 * $intLoop), 300, 15) Next Local $btn_OK = GUICtrlCreateButton("&Ok", 25, 70 + (18 * $aXLWindows[0][0]), 50, 25) Local $btn_Cancel = GUICtrlCreateButton("&Cancel", 275, 70 + (18 * $aXLWindows[0][0]), 50, 25) GUISetState(@SW_SHOW) While 1 Sleep(10) Switch GUIGetMsg() ; When OK is pressed, read the GUI for whatever Radio is checked and return that one's attached HWND. Case $btn_OK GUISetState(@SW_HIDE) For $intLoop = 1 To $rad_XL[0] If GUICtrlRead($rad_XL[$intLoop]) = $GUI_CHECKED Then Return $aXLWindows[$intLoop][1] EndIf Next MsgBox(0, "", "Please select an option from the list or press cancel") GUISetState(@SW_SHOW) Case $GUI_EVENT_CLOSE, $btn_Cancel SetError(2) Return "" EndSwitch WEnd GUIDelete() EndFunc ;==>_guiXLChoice Func _XLDetect() Local $winMatchMode = Opt("WinTitleMatchMode"), $a_Return Opt("WinTitleMatchMode", 4) $a_Return = WinList("[CLASS:XLMAIN]") If $a_Return[0][0] > 0 Then SetError(0) Opt("WinTitleMatchMode", $winMatchMode) Return $a_Return Else SetError(1) Opt("WinTitleMatchMode", $winMatchMode) Return "" EndIf EndFunc ;==>_XLDetect Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
Blue_Drache Posted July 16, 2007 Author Share Posted July 16, 2007 Ok, thanks for the help so far! Still haven't had any luck, does anyone else have any additional input? Maybe some laughter because this is a brick wall with a bloodstain on it from me beating my forehead across the mortar? Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted July 17, 2007 Moderators Share Posted July 17, 2007 Ok, thanks for the help so far! Still haven't had any luck, does anyone else have any additional input?Maybe some laughter because this is a brick wall with a bloodstain on it from me beating my forehead across the mortar?I'll see what I can come up with when I get home. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now