m0raca Posted May 23, 2009 Posted May 23, 2009 So I am trying to do something simple.I want to simply copy a value from excel in to the copy/paste buffer.I have read the "examples" from http://www.autoitscript.com/forum/index.ph...st&id=18417 and quite frankly I am loosing my hair trying to even use any of these functions.Any help or guidance would be greatly appreciated.Thanks,m0
Valuater Posted May 23, 2009 Posted May 23, 2009 We need an example script from you to show us what direction you were going. .... We can't read minds and write anything that will work for you. 8)
m0raca Posted May 23, 2009 Author Posted May 23, 2009 (edited) We need an example script from you to show us what direction you were going. .... We can't read minds and write anything that will work for you.8)Sure. I am starting here by trying to attach to the spreadsheet I want Book2.xls.CODE#include <Excel.au3>#include <File.au3>Func _ExcelAttach($s_string, $s_mode = "Title") $s_mode = StringLower($s_mode) Local $o_Result, $o_workbook, $o_workbooks $o_Result = ObjGet("", "Excel.Application") If @error Or Not IsObj($o_Result) Then ConsoleWrite("Unable to attach to existing Excel.Application object." & @CR) Return SetError(1, 0, 0) EndIf $o_workbooks = $o_Result.Application.Workbooks If Not IsObj($o_workbooks) Or $o_workbooks.Count = 0 Then ConsoleWrite("There were no open excel windows." & @CR) Return SetError(1, 0, 0) EndIf;~ ConsoleWrite($o_workbooks.count & @CR) For $o_workbook In $o_workbooks Switch $s_mode Case "filename";~ ConsoleWrite($o_workbook.Name & @CR) If $o_workbook.Name = $s_string Then $o_workbook.Activate Return $o_workbook.Application EndIf Case "filepath";~ ConsoleWrite($o_workbook.FullName & @CR) If $o_workbook.FullName = $s_string Then $o_workbook.Activate Return $o_workbook.Application EndIf Case "title";~ ConsoleWrite($o_workbook.Application.Caption & @CR) If ($o_workbook.Application.Caption) = $s_string Then $o_workbook.Activate Return $o_workbook.Application EndIf Case Else ; Invalid Mode ConsoleWrite("You have specified an invalid mode." & @CR) Return SetError(1, 0, 0) EndSwitch Next Return SetError(1, 0, 0)EndFunc ;==>_ExcelAttach$oExcel = _ExcelBookAttach("Microsoft Excel - Book2", "Title") ;with $s_mode = "Title" ==> Title of the Excel window_ExcelWriteCell($oExcel, "If you can read this, then Success!", 1, 1) ;Write to the CellI have Book2 open when executing this macro. Edited May 23, 2009 by m0raca
Valuater Posted May 23, 2009 Posted May 23, 2009 Good that was some effort... I lied, here is an example of what you asked for..I want to simply copy a value from excel in to the copy/paste buffer.#include <Excel.au3> Local $oExcel = _ExcelBookNew() ;Create new book, make it visible For $i = 1 To 5 ;Loop _ExcelWriteCell($oExcel, $i, $i, 1) ;Write to the Cell Next For $i = 1 To 5 ;Loop $sCellValue = _ExcelReadCell($oExcel, $i, 1) MsgBox(0, "", "The Cell Value is: " & @CRLF & $sCellValue, 2) Next MsgBox(0, "Exiting", "Press OK to Save File and *Copy To Clipboard* then Exit") ClipPut($sCellValue) _ExcelBookSaveAs($oExcel, @TempDir & "\Temp.xls", "xls", 0, 1) ; Now we save it into the temp directory; overwrite existing file if necessary _ExcelBookClose($oExcel) ; And finally we close out ; USE CTRL + V TO PASTE THE READ FROM CELL #58)
m0raca Posted May 23, 2009 Author Posted May 23, 2009 Good that was some effort... I lied, here is an example of what you asked for.. I want to simply copy a value from excel in to the copy/paste buffer. #include <Excel.au3> Local $oExcel = _ExcelBookNew() ;Create new book, make it visible For $i = 1 To 5 ;Loop _ExcelWriteCell($oExcel, $i, $i, 1) ;Write to the Cell Next For $i = 1 To 5 ;Loop $sCellValue = _ExcelReadCell($oExcel, $i, 1) MsgBox(0, "", "The Cell Value is: " & @CRLF & $sCellValue, 2) Next MsgBox(0, "Exiting", "Press OK to Save File and *Copy To Clipboard* then Exit") ClipPut($sCellValue) _ExcelBookSaveAs($oExcel, @TempDir & "\Temp.xls", "xls", 0, 1) ; Now we save it into the temp directory; overwrite existing file if necessary _ExcelBookClose($oExcel) ; And finally we close out ; USE CTRL + V TO PASTE THE READ FROM CELL #5 8) Hey thanks for your help... I am on the road now, somewhat. I can get what I need in and out of Excel and see the variables to increment where needed when I want to pull new info from excel on the next cell down. Now any suggested threads to figure out IE and frames? Not looking for code necessarily, just guidance. Now that I have the data from excel I need to plug it in to an annoying web page.
Moderators big_daddy Posted May 25, 2009 Moderators Posted May 25, 2009 Now any suggested threads to figure out IE and frames?Just work through some of the examples in the help file._IEFrameGetObjByName or _IEFrameGetCollection
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