laffo16 Posted December 7, 2007 Posted December 7, 2007 yes, i tend to use the example provided in help file. send("{pause}") just provides and easy way of looping the script at specific points while i test the accessability of other excel docs. Global $Paused HotKeySet("{PAUSE}", "TogglePause") Func TogglePause() $Paused = NOT $Paused While $Paused sleep(100) ToolTip('Script is "Paused"',0,0) WEnd ToolTip("") EndFunc
ptrex Posted December 7, 2007 Posted December 7, 2007 @Laffo16A bit late but I created an example on how to get the best speed to get the nr. of Records counted in excel.Reading Excel data using SQLRegardsptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
ChrisJakarta Posted January 1, 2008 Posted January 1, 2008 Thanks for a very useful set of routines. However, I did experience a couple of problems, one significant (assuming I go the latest version: v1.32, 02-12-07): 1. _ExcelFindInRange calls the Excel routine ".Selection.Find". I have found the last parameter of this ($fMatchFormat in the UDF, MatchByte in the Excel routine) must be removed. In the Excel VB Help file, it states: "Used only if youve selected or installed double-byte language support." Not sure what that means, and perhasp its a problem because I'm still using Excel 2000, but including this parameter caused failure. Deleting ",$fMatchFormat" in several places in the UDF seemed to be the only solution. As far as I can see, this does not harm. 2. (Nit-picking) In the description of _ExcelBookSaveAs, the syntax shows "_ExcelSaveDocAs". You may wish to correct this. Chris
Blue_Drache Posted January 3, 2008 Posted January 3, 2008 One small hiccup that may need to be corrected. When using Opt("MustDeclareVars",1) the _ExcelOpen* commands toss out an undeclared variable error for the $oExcel variable. I've corrected my local copy by adding a "Local" dim statment in front of the $oExcel = ObjCreate() commands. Thank you for the excellent UDF file, Darwin! Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
PsaltyDS Posted January 4, 2008 Posted January 4, 2008 Yet another 2D Array read from an Excel spreadsheet. Reposted here from another topic:I'm trying to learn some of the Office COM interface stuff from Locodarwin's excellent example. This is my attempt to morph his _ExcelReadArray() function into a 2D array that can read the entire active sheet by default, or be told to read a 2D range:expandcollapse popup;=============================================================================== ; ; Description: Create a 2D array from the rows/columns of the active worksheet. ; Syntax: _ExcelReadSheetToArray($oExcel, [$iStartRow , $iStartColumn [, $iRowCnt, $iColCnt]]) ; Parameter(s): $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew() ; $iStartRow - Row number to start reading, defaults to 1 (first row) ; $iStartColumn - Column number to start reading, defaults to 1 (first column) ; $iRowCnt - Count of rows to read, defaults to 0 (all) ; $iColCnt - Count of columns to read, defaults to 0 (all) ; Requirement(s): Requires ExcelCOM_UDF.au3 ; Return Value(s): On Success - Returns a 2D array with the specified cell contents by [$row][$col] ; On Failure - Returns 0 and sets @error on errors: ; @error=1 - Specified object does not exist ; @error=2 - Start parameter out of range ; @extended=0 - Row out of range ; @extended=1 - Column out of range ; @error=3 - Count parameter out of range ; @extended=0 - Row count out of range ; @extended=1 - Column count out of range ; Author(s): SEO <locodarwin at yahoo dot com> (original _ExcelReadArray() function) ; Modified: PsaltyDS 01/04/08 - 2D version _ExcelReadSheetToArray() ; Note(s): Returned array has row count in [0][0] and column count in [0][1]. ; Except for the counts above, row 0 and col 0 of the returned array are empty, as actual ; cell data starts at [1][1] to match R1C1 numbers. ; By default the entire sheet is returned. ; If the sheet is empty [0][0] and [0][1] both = 0. ; ;=============================================================================== Func _ExcelReadSheetToArray($oExcel, $iStartRow = 1, $iStartColumn = 1, $iRowCnt = 0, $iColCnt = 0) Local $avRET[1][2] = [[0, 0]] ; 2D return array ; Test inputs If Not IsObj($oExcel) Then Return SetError(1, 0, 0) If $iStartRow < 1 Then Return SetError(2, 0, 0) If $iStartColumn < 1 Then Return SetError(2, 1, 0) If $iRowCnt < 0 Then Return SetError(3, 0, 0) If $iColCnt < 0 Then Return SetError(3, 1, 0) ; Get size of current sheet as R1C1 string ; Note: $xlCellTypeLastCell and $x1R1C1 are constants declared in ExcelCOM_UDF.au3 Local $sLastCell = $oExcel.Application.Selection.SpecialCells($xlCellTypeLastCell).Address(True, True, $xlR1C1) ; Extract integer last row and col Local $iLastRow = StringInStr($sLastCell, "R") Local $iLastColumn = StringInStr($sLastCell, "C") $iLastRow = Number(StringMid($sLastCell, $iLastRow + 1, $iLastColumn - $iLastRow - 1)) $iLastColumn = Number(StringMid($sLastCell, $iLastColumn + 1)) ; Return 0's if the sheet is blank If $sLastCell = "R1C1" And $oExcel.Activesheet.Cells($iLastRow, $iLastColumn).Value = "" Then Return $avRET ; Check input range is in bounds If $iStartRow > $iLastRow Then Return SetError(2, 0, 0) If $iStartColumn > $iLastColumn Then Return SetError(2, 1, 0) If $iStartRow + $iRowCnt - 1 > $iLastRow Then Return SetError(3, 0, 0) If $iStartColumn + $iColCnt - 1 > $iLastColumn Then Return SetError(3, 1, 0) ; Check for defaulted counts If $iRowCnt = 0 Then $iRowCnt = $iLastRow - $iStartRow + 1 If $iColCnt = 0 Then $iColCnt = $iLastColumn - $iStartColumn + 1 ; Size the return array ReDim $avRET[$iRowCnt + 1][$iColCnt + 1] $avRET[0][0] = $iRowCnt $avRET[0][1] = $iColCnt ; Read data to array For $r = 1 To $iRowCnt For $c = 1 To $iColCnt $avRET[$r][$c] = $oExcel.Activesheet.Cells($iStartRow + $r - 1, $iStartColumn + $c - 1).Value Next Next ;Return data Return $avRET EndFunc ;==>_ExcelReadSheetToArrayTo read the entire current active sheet, just do: _ExcelReadSheetToArray($oExcel)To read a 3x3 cell block starting at R7C9: _ExcelReadSheetToArray($oExcel, 7, 9, 3, 3)To read the rest of the sheet from R7C9 to the end: _ExcelReadSheetToArray($oExcel, 7, 9)To read two rows from R7C9 to the last column: _ExcelReadSheetToArray($oExcel, 7, 9, 2)To read two columns from R7C9 to the last row: _ExcelReadSheetToArray($oExcel, 7, 9, 0, 2)Hope that helps. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
PsaltyDS Posted January 5, 2008 Posted January 5, 2008 And the complementary function _ExcelWriteSheetFromArray(): expandcollapse popup;=============================================================================== ; ; Description: Writes a 2D array to the active worksheet ; Syntax: _ExcelWriteSheetFromArray($oExcel, ByRef $aArray [, $iStartRow = 1, $iStartColumn = 1 [, $iRowBase = 1, $iColBase = 1]]) ; Parameter(s): $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew() ; $aArray - The array ByRef to write data from (array is not modified) ; $iStartRow - The table row to start writing the array to, default is 1 ; $iStartColumn - The table column to start writing the array to, default is 1 ; $iRowBase - array index base for rows, default is 1 ; $iColBase - array index base for columns, default is 1 ; Requirement(s): ExcelCOM_UDF.au3 ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 and sets @error on errors: ; @error=1 - Specified object does not exist ; @error=2 - Parameter out of range ; @extended=0 - $iStartRow out of range ; @extended=1 - $iStartColumn out of range ; @error=3 - Array invalid ; @extended=0 - doesn't exist / variable is not an array ; @extended=1 - not a 2D array ; @error=4 - Base index out of range ; @extended=0 - $iRowBase out of range ; @extended=1 - $iColBase out of range ; Author(s): SEO <locodarwin at yahoo dot com> (original ExcelWriteArray() function) ; Modified: PsaltyDS 01/04/08 - 2D version _ExcelWriteSheetFromArray() ; Note(s): Default base indexes in the array are both = 1, so first cell written is from $aArray[1][1]. ; ;=============================================================================== Func _ExcelWriteSheetFromArray($oExcel, ByRef $aArray, $iStartRow = 1, $iStartColumn = 1, $iRowBase = 1, $iColBase = 1) ; Test inputs If Not IsObj($oExcel) Then Return SetError(1, 0, 0) If $iStartRow < 1 Then Return SetError(2, 0, 0) If $iStartColumn < 1 Then Return SetError(2, 1, 0) If Not IsArray($aArray) Then Return SetError(3, 0, 0) Local $iDims = UBound($aArray, 0), $iLastRow = UBound($aArray, 1) - 1, $iLastColumn = UBound($aArray, 2) - 1 If $iDims <> 2 Then Return SetError(3, 1, 0) If $iRowBase > $iLastRow Then Return SetError(4, 0, 0) If $iColBase > $iLastColumn Then Return SetError(4, 1, 0) For $r = $iRowBase To $iLastRow $iCurrCol = $iStartColumn For $c = $iColBase To $iLastColumn $oExcel.Activesheet.Cells($iStartRow, $iCurrCol).Value = $aArray[$r][$c] $iCurrCol += 1 Next $iStartRow += 1 Next Return 1 EndFunc ;==>_ExcelWriteSheetFromArray This one hasn't been tested yet because I wrote it on request, and I don't have Excel here right now. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Locodarwin Posted January 5, 2008 Author Posted January 5, 2008 ChrisJakarta: I understand your situation. In the next release the function will accommodate those who do not have double-byte language support installed. I've also fixed the header for _ExcelBookSaveAs(). Blue Drache: I've added the scope statement "Local" in front of all of the $oExcel variables in the functions that needed it. Thanks for pointing that out. PSaltyDS: Your functions are excellently written and very useful. I'd like to include them in the UDF with your permission. _ExcelWriteSheetFromArray() will have to be tested first, of course. If someone wouldn't mind doing so while I'm work on some other improvements, that'd be great. The next release of the UDF will be released hopefully later today and will contain some improvements, bug fixes, and some new functions related to printing, password protection, and workbook sharing among other things. These were among the most requested features and changes. I was asked how far along I am with regard to submitting the UDF to the development team for distribution with AutoIt. Basically, I'm about halfway through the help documentation and I have quite a few example scripts left to write up. It looks like most of the bugs in the existing code have been ironed out, thanks to feedback from the community. I have a pretty good bank of time (for the first time in a long time) available over the next couple of weeks to wrap this up for submission. Therefore, the request lines are open. If there's something you'd like to see in the UDF before it gets submitted, please reply. Contributions are always appreciated as well. -S (Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]
PsaltyDS Posted January 5, 2008 Posted January 5, 2008 @Locodarwin: Feel free to include those and mod them as you see fit. Do please test the way the arrays are created in _ExcelReadSheetToArray() and therefore how they are read from by default in _ExcelWriteSheetFromArray(). The use of [1][1] vice [0][0] as the base element seemed to solve a lot of problems for me, but I don't know if everyone would agree on my decision (I still think it works best in the spreadsheet paradigm). You should consider something along the lines of Dale's _IE_Example() function. Although it must have been a pain to write, I'm guessing it saved a lot of work in writing the examples for his help file. PM me if there's anything I can do to help (despite the fact I don't have MS Office at home!). Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Locodarwin Posted January 6, 2008 Author Posted January 6, 2008 (edited) Update: v1.4 released! Please see first post for attachment and changelog. Thanks to contributors big_daddy and PsaltyDS. -S Edited January 6, 2008 by Locodarwin (Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]
everseeker Posted January 10, 2008 Posted January 10, 2008 Possible bug... Here's my Script (Clipped out large sections that are not related...) Could there be an [issue with/bug in] the new version of ExcelCom_UDF?? expandcollapse popup#cs --------------------------------------------------------- Title: RCBulkTest.au3 AutoIt Version: 3.2.10.0 Author: Patrick McCarthy Company: HumanaOne Script Function: Bulk Rate test for Rate Calculator Script Version: 0.0.3 Initiated: 01/03/08 Last Update: 01/10/08 *** ExcelCOM_UDF.au3 Microsoft Excel COM UDF library for AutoIt v3 *** Current Ver: 1.4 *** Thanks to SEO aka Locodarwin, DaLiMan, Stanley Lim, MikeOsdx, MRDev, big_daddy, and PsaltyDS #ce --------------------------------------------------- Opt("GUIOnEventMode", 1) #include <GUIConstants.au3> ; Load the standard Constants pack #include <ExcelCOM_UDF.au3> ; Include the Microsoft Excel COM UDF library for AutoIt v3 Global $oExcel = 1 Global $Counter = 1 Global $array[10] ;Open the Excel file _ExcelBookOpen(FileOpenDialog("Load Excel Data File", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "Data(*.xls)", 1, "RC Test Cases KY set.XLS"), 1, "False") ;Find the last cell $array = _excelSheetUsedRangeGet($oExcel, 1) ConsoleWrite(_VarDump($array)) Global $Rows = ($array[3]) Global $Cols = ($array[2]) Global $MasterArray[$Rows][$Cols] ConsoleWrite(_VarDump($MasterArray)) ;Load the entire Spreadsheet to the master array $MasterArray = _ExcelReadSheetToArray($oExcel) ;Load the random child genders For $Index = 1 To $array[3] For $KidIndex = 60 To 69 $MasterArray[$Index][$KidIndex] = PickGender() Next Next ;Data loaded, now hide the Excel spreadsheet _excelHide($oExcel) #cs --------------------------------------------------------- [Clip] Launch Rate Calc and process the array #ce --------------------------------------------------------- #cs ---------------------------------------------------------------------------- Following is the function collection... #ce ---------------------------------------------------------------------------- Func PickGender() If Random(0, 2) <= 1 Then Return "M" Else Return "F" EndIf EndFunc ;==>PickGender Func _VarDump(ByRef $vVar, $sIndent = '') Select Case IsDllStruct($vVar) Return 'Struct(' & DllStructGetSize($vVar) & ')' Case IsArray($vVar) Return 'Array' & @CRLF & _VarDumpArray($vVar, $sIndent) Case IsBinary($vVar) Return 'Binary(' & BinaryLen($vVar) & ')' Case IsBool($vVar) Return 'Boolean(' & $vVar & ')' Case IsFloat($vVar) Return 'Float(' & $vVar & ')' Case IsHWnd($vVar) Return 'HWnd(' & $vVar & ')' Case IsInt($vVar) Return 'Integer(' & $vVar & ')' Case IsKeyword($vVar) Return 'Keyword(' & $vVar & ')' Case IsObj($vVar) Return 'Object(' & ObjName($vVar) & ')' Case IsString($vVar) Return 'String(' & StringLen($vVar) & ') ' & $vVar Case Else Return 'Unknown(' & $vVar & ')' EndSelect EndFunc ;==>_VarDump Func _VarDumpArray(ByRef $aArray, $sIndent = '') Local $sDump Local $sArrayFetch, $sArrayRead, $bDone Local $iSubscripts = UBound($aArray, 0) Local $aUBounds[$iSubscripts] Local $aCounts[$iSubscripts] $iSubscripts -= 1 For $i = 0 To $iSubscripts $aUBounds[$i] = UBound($aArray, $i + 1) - 1 $aCounts[$i] = 0 Next $sIndent &= @TAB While 1 $bDone = True $sArrayFetch = '' For $i = 0 To $iSubscripts $sArrayFetch &= '[' & $aCounts[$i] & ']' If $aCounts[$i] < $aUBounds[$i] Then $bDone = False Next $sArrayRead = Execute('$aArray' & $sArrayFetch) If @error Then ExitLoop Else $sDump &= $sIndent & $sArrayFetch & ' => ' & _VarDump($sArrayRead, $sIndent) If Not $bDone Then $sDump &= @CRLF Else Return $sDump EndIf EndIf For $i = $iSubscripts To 0 Step - 1 $aCounts[$i] += 1 If $aCounts[$i] > $aUBounds[$i] Then $aCounts[$i] = 0 Else ExitLoop EndIf Next WEnd EndFunc ;==>_VarDumpArray When I run the script, I get the following output Note the 'Integer(0)' (So, it looks like the line: $array = _excelSheetUsedRangeGet($oExcel, 1) returns an integer?) >"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\pbm0869\My Documents\Auto IT 3 work\RCBulkTest.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams +>10:49:20 Starting AutoIt3Wrapper v.1.9.4 >Running AU3Check (1.54.10.0) from:C:\Program Files\AutoIt3 +>10:49:20 AU3Check ended.rc:0 >Running:(3.2.10.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\pbm0869\My Documents\Auto IT 3 work\RCBulkTest.au3" Integer(0)C:\Documents and Settings\pbm0869\My Documents\Auto IT 3 work\RCBulkTest.au3 (109) : ==> Subscript used with non-Array variable.: Global $Rows = ($array[3]) Global $Rows = ($array^ ERROR ->10:49:31 AutoIT3.exe ended.rc:1 +>10:49:32 AutoIt3Wrapper Finished >Exit code: 1 Time: 12.851 Of course, it could be me.... Am I doing something wrong? Everseeker
/dev/null Posted January 10, 2008 Posted January 10, 2008 Possible bug...Of course, it could be me.... Am I doing something wrong?http://www.autoitscript.com/forum/index.ph...mp;#entry461412 __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
Locodarwin Posted January 10, 2008 Author Posted January 10, 2008 Good catch, /dev/null. -S (Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]
sensalim Posted January 10, 2008 Posted January 10, 2008 Can this read/write DBF (dBase IV) files? I searched and ones I found are no longer working... it was prior to autoit latest version.
ChrisJakarta Posted January 13, 2008 Posted January 13, 2008 Thanks, Locodarwin, v1.4 seems to correct my problem with _ExcelFindInRange. One other comment if I may: If a workbook is opened as hidden ($fVisible = 0), and subsequently an error occurs so that the workbook is not properly closed, I have found no way to close it or re-open it without forcing Excel to close or re-booting. Am I missing something? Perhaps an error handler is needed to trap this? In the meantime, I've tried to include appropriate error handling in the calling routine.... Chris
therks Posted January 13, 2008 Posted January 13, 2008 expandcollapse popup... Func _VarDump(ByRef $vVar, $sIndent = '') Select Case IsDllStruct($vVar) Return 'Struct(' & DllStructGetSize($vVar) & ')' Case IsArray($vVar) Return 'Array' & @CRLF & _VarDumpArray($vVar, $sIndent) Case IsBinary($vVar) Return 'Binary(' & BinaryLen($vVar) & ')' Case IsBool($vVar) Return 'Boolean(' & $vVar & ')' Case IsFloat($vVar) Return 'Float(' & $vVar & ')' Case IsHWnd($vVar) Return 'HWnd(' & $vVar & ')' Case IsInt($vVar) Return 'Integer(' & $vVar & ')' Case IsKeyword($vVar) Return 'Keyword(' & $vVar & ')' Case IsObj($vVar) Return 'Object(' & ObjName($vVar) & ')' Case IsString($vVar) Return 'String(' & StringLen($vVar) & ') ' & $vVar Case Else Return 'Unknown(' & $vVar & ')' EndSelect EndFunc ;==>_VarDump Func _VarDumpArray(ByRef $aArray, $sIndent = '') Local $sDump Local $sArrayFetch, $sArrayRead, $bDone Local $iSubscripts = UBound($aArray, 0) Local $aUBounds[$iSubscripts] Local $aCounts[$iSubscripts] $iSubscripts -= 1 For $i = 0 To $iSubscripts $aUBounds[$i] = UBound($aArray, $i + 1) - 1 $aCounts[$i] = 0 Next $sIndent &= @TAB While 1 $bDone = True $sArrayFetch = '' For $i = 0 To $iSubscripts $sArrayFetch &= '[' & $aCounts[$i] & ']' If $aCounts[$i] < $aUBounds[$i] Then $bDone = False Next $sArrayRead = Execute('$aArray' & $sArrayFetch) If @error Then ExitLoop Else $sDump &= $sIndent & $sArrayFetch & ' => ' & _VarDump($sArrayRead, $sIndent) If Not $bDone Then $sDump &= @CRLF Else Return $sDump EndIf EndIf For $i = $iSubscripts To 0 Step - 1 $aCounts[$i] += 1 If $aCounts[$i] > $aUBounds[$i] Then $aCounts[$i] = 0 Else ExitLoop EndIf Next WEnd EndFunc ;==>_VarDumpArray Hey that's my VarDump stuff. Glad to see it's being used. Although sad I don't get a mention. My AutoIt Stuff | My Github
laffo16 Posted January 25, 2008 Posted January 25, 2008 hello! i'm trying to use the print function with Acrobat Distiller, to create a pdf file. it selects printer "Acrobat Distiller", sends to print. Then i get "File Save As" window, at this point, autoit is frozen unable to move on. If i click Save, it continues, but i want to automate the controlclick of save (which im unable to). If i click Cancel it bottles out and sends: $oExcel.ActiveSheet.PrintOut(Default, Default, $iCopies, False, $sActivePrinter, $fPrintToFile, $fCollate, $sPrToFileName)^ Error: The requested action with object has failed. any ideas how i might get around this? any help appreciated. i noticed autoit will only continue after the print has finished sending. maybe if the error could be handled i could continue from "file save as" window.
ending Posted January 26, 2008 Posted January 26, 2008 These don't seem to work with Excel 2007. _ExcelSheetActivate() _ExcelCopy() _ExcelInsert() ExcelCOM_UDF.au3 (2191) : ==> The requested action with this object has failed.: If $oExcel.ActiveWorkbook.Sheets.Count < $vSheet Then Return SetError(2, 0, 0) If $oExcel.ActiveWorkbook^ ERROR I don't think its a problem with my code because _ExcelReadCell() works perfect on the object. Here's the code I'm using: Func _ExecuteExcelManipulation() IF NOT FileExists($FileName) Then Msgbox (0,"Error","The following file cannot be opened "& $FileName) Return False EndIf $oExcelDoc = ObjGet($FileName); Get an Excel Object from an existing filename If @error Then Msgbox (48,"Errer","Error Getting an active Excel Object. Error code: " & hex(@error,8)) Exit EndIf $oExcelDoc.Windows(1).Visible = 1; Set the first worksheet in the workbook visible $oExcelDoc.Application.Visible = 1; Set the application visible (without this Excel will exit) MsgBox(0,"",_ExcelReadCell($oExcelDoc,5,3));this works here ;change sheet to correct one _ExcelSheetActivate($oExcelDoc,$Sheet) _ExcelCopy($oExcelDoc,_TranslateLetterToNumber($S_SC),$S_SR,_TranslateLetterToNumber($S_EC),$S_ER) _ExcelInsert($oExcelDoc,_TranslateLetterToNumber($D_SC),$D_SR,$xlShiftDown) EndFunc
Locodarwin Posted January 29, 2008 Author Posted January 29, 2008 @laffo16: I'm sorry, but I can't really offer any help with your scenario. My functions assume your printer (in your case, a software substitute) does not require further user intervention after the print call.@ending: _ExcelSheetActivate(), _ExcelCopy(), and _ExcelInsert() all work fine for me using Office 2007. I use these functions regularly myself.Perhaps you should post some code snippets which reproduce what you're seeing, so that we can figure out why it's not working for you.-S (Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]
ending Posted January 30, 2008 Posted January 30, 2008 (edited) Your example scripts weren't working for me either, so I got irritated and reinstalled Office and re-dowloaded the UDF. Now they're working fine . Sorry to be a pest, but I knew I was doing everything right since your example scripts were doing the same thing. I didnt change any of the functions other than ActivateSheet so it might have been a bad installation of Office or something. Thanks for being patient. Edited January 30, 2008 by ending
Locodarwin Posted January 30, 2008 Author Posted January 30, 2008 @ending: On the one hand, I'm sorry to hear about your woes. On the other hand, I'm glad to hear you were able to resolve the issue.Good luck with your Excel endeavors!-S (Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]
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