Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
IDispatch exception code 0
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00612215
Message ID:
00612347
Views:
19
Working from the SCX I am not able to reproduce this behavior.
Are you sure you do not have already another sheet with the very same name? What is the error message exactly?


>An Excel automation issue/question ...
>
>I downloaded some code off the FoxWiki and used it for the basis of a function (below) to auto-adjust the widths of columns in a VFP-generated XLS file and also to set the worksheet name.
>
>It works great at the command prompt, but when this function is called from within an SCX I get an error message of "OLE IDispatch exception code 0 from ?: ?..". The error occurs on a property assignment statement (for the worksheet name) as shown below.
>
>If anybody has a suggestion, I'd love to hear it.
>
>Thanks - Doug
>
>*procedure ExcelFix.prg
>* Inputs: 1st parameter = filename (existing Excel file)
>* 2nd parameter = worksheet name (to be set in the file; optional)
>* 3rd parameter = whether to display the file in Excel
>* Output: The file is opened, column widths are adjusted, the worksheet name is
>* set (if specified) and the file is saved in the latest Excel format.
>lparameters lcFilename , lcSheetName , llDisplay
>lcSheetName = iif( type('lcSheetName')='C' , lcSheetName , '' )
>
>local lnXlMaximize , lnXlLastCell
>lnXlMaximize = -4137
>lnXlLastCell = 11
>
>local loExcel
>loExcel = CreateObject('Excel.Application')
>if vartype(loExcel)<>'O'
> ErrMsg( 'Microsoft Excel failed to run!' )
> return .F.
>endif
>
>loExcel.SheetsInNewWorkBook = 1
>loWorkbook = loExcel.Workbooks.Open(lcFilename)
>oActiveSheet = loExcel.ActiveSheet
>if !empty(lcSheetName)
> ************** CRASHES ON THE LINE BELOW: ******************
> oActiveSheet.Name = lcSheetName
>endif
>
>* resize all columns ...
>lcLastCell = loExcel.ActiveCell.SpecialCells(lnXlLastCell).Address() && address of last occupied cell
>lnMarker1 = at('$',lcLastCell,1) && i.e. 1 when lcLastCell = "$AF$105"
>lnMarker2 = at('$',lcLastCell,2) && i.e. 4 when lcLastCell = "$AF$105"
>lnStartPos = lnMarker1 + 1
>lnStrLen = lnMarker2 - lnStartPos
>loExcel.Columns('A:' + substr(lcLastCell,lnStartPos,lnStrLen)).EntireColumn.AutoFit
>
>if llDisplay
> loExcel.Application.WindowState = lnXlMaximize
> loExcel.visible = .T.
>endif
>
>* save Excel file in new Excel format (COPY TO XLS uses old format) ...
>loWorkbook.Save()
>
>return
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform