reb Posted October 14, 2009 Share Posted October 14, 2009 (edited) HiI want to run a script and attach to an open excel spreadsheet. See my problem in script below.#include <Excel.au3>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DEMO THAT SHEETACTIVATE WORKS IF BOOK IS OPENED BY SCRIPT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;$oExcel = _ExcelBookNew()_ExcelBookSaveAs($oExcel, @TempDir & "\Temp.xls", "xls", 0, 1)_ExcelWriteCell($oExcel, "I Wrote to This Cell", 1, 1)$sCellValue = _ExcelReadCell($oExcel, 1, 1)MsgBox(0, "", "The Cell Value is: " & @CRLF & $sCellValue & @CRLF & "Will now switch to sheet2", 4)_ExcelSheetActivate($oExcel, 2)MsgBox(0, "Exiting", "Switched to Sheet2 Press OK to Save File and Exit")_ExcelBookClose($oExcel);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DEMO SCRIPT FAIL TO ACTIVATE A SHEET WHEN BOOK ATTACH IS USED ON AN OPEN BOOK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;$bBook = @TempDir & "\Temp.xls"$oExcel = _ExcelBookOpen($bBook)MsgBox(0,"",'WORKBOOK REOPENED AND WILL WRITE TO ROW 2 COL 1')_ExcelWriteCell($oExcel, "I Wrote to This Cell JUST NOW", 2, 1)MsgBox(0, "", "ExcelWriteCell WORKS HERE" & @CRLF & "WILL NOW TRY TOO ACTIVATE SHEET2", 1, 1)$bBook = @TempDir & "\Temp.xls"$oExcel = _ExcelBookAttach(@TempDir & "\Temp.xls")WinWait("Microsoft Excel - Temp.xls", "")If Not WinActive("Microsoft Excel - Temp.xls", "") Then WinActivate("Microsoft Excel - Temp.xls", "")WinWaitActive("Microsoft Excel - Temp.xls", ""); SCRIPT WILL FAIL HERE_ExcelSheetActivate($oExcel, 2)MsgBox(0, "", "DID I ACTIVATE SHEET2?", 2)_ExcelBookClose($oExcel)Exit;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; THE SAME PROBLEM EXISTS WITH $oExcel.RUN(A FILE) ; WORKS IF BOOK IS OPENED BY SCRIPT ; DOES NOT WORK WHEN BOOK ATTACH IS USED ON AN OPEN BOOK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ThanksREBFound the solution to my problem hereMy link post #5REB Edited October 14, 2009 by reb MEASURE TWICE - CUT ONCE 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