Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
OLE Message in Excel 2002
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00822245
Message ID:
00822324
Vues:
16
Thanks Gregory. That did the trick, and I appreciate the extra info, it looks useful.
- Dave

>>I have a routine in VFP that uses Excel Automation to do some data manipulation on an exported Excel workbook. I’m using the REPLACE automation function to change values in a selected range of cells. My code looks something like this…
>>
>>loExcelApp = CREATEOBJECT(“Excel.Application”)
>>loWorkbook = loExcelApp.Workbooks.Open("D:\My Documents\XLFile.xls")
>>loExcelApp.Range('A1:Z1').Select
>>loExcelApp.Selection.Replace('Year 1', '2003')
>>
>>When running Excel 2002, a dialog message often appears saying: “Microsoft Excel cannot find any data to replace. Check if your search formatting and criteria are defined correctly…”. I believe the reason for this message is that the character string (“Year 1” in the code above) isn’t contained in any of the cells being searched, which is likely given what I'm attempting to do. However, I want Excel to simply continue silently when nothing is found, and not prompt me or my users. If Excel 2000 or Excel 97 are used as the automation engine this message didn't get generated, so it appears to be something added by MS in this latest Excel release.
>>
>>This message is very annoying and, in my opinion kind of useless, and I’d very much like to avoid its generation. I’d either like to know a way of turning it off, preferably via automation code, or adding code to check to see if the original text exists in the first place, and if not, skipping the replace function altogether. Can anyone help?
>>
>>TIA
>>- Dave
>
>
>Dave,
>
>
>>loExcelApp = CREATEOBJECT(“Excel.Application”)
>>loWorkbook = loExcelApp.Workbooks.Open("D:\My Documents\XLFile.xls")
>
>local DisplayAlerts
>DisplayAlerts = loExcelApp.DisplayAlerts
>loExcelApp.DisplayAlerts= .f.
>
>>loExcelApp.Range('A1:Z1').Select
>>loExcelApp.Selection.Replace('Year 1', '2003')
>loExcelApp.DisplayAlerts=DisplayAlerts
>
>
>
>Am adding the function I always use as an example
>
>&& expression.Replace(What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte, SearchFormat, ReplaceFormat)
>&& expression   Required. An expression that returns a Range object.
>
>&& What  Required Variant. The string you want Microsoft Excel to search for.
>
>&& Replacement  Required Variant.  The replacement string.
>
>&& LookAt   Optional Variant. Can be one of the following XlLookAt constants: xlWhole or xlPart.
>
>&& SearchOrder   Optional Variant. Can be one of the following XlSearchOrder constants: xlByRows or xlByColumns.
>
>&& MatchCase   Optional Variant. True to make the search case sensitive.
>
>&& MatchByte   Optional Variant. You can use this argument only if you’ve selected or installed double-byte language support in Microsoft Excel
>				&& True to have double-byte characters match only double-byte characters. False to have double-byte characters match their single-byte equivalents.
>
>&& SearchFormat  Optional Variant. The search format for the method.
>
>&& ReplaceFormat  Optional Variant. The replace format for the method.
>
>* XlLookAt
>#DEFINE xlPart  2
>#DEFINE xlWhole  1
>
>* XlSearchOrder
>#DEFINE xlByColumns  2
>#DEFINE xlByRows  1
>
>function SearchAndReplace_ExcelSheet
>	lparameters	ExcelSheet, SearchFor, ReplaceWith, MatchCase, MatchWholeWord
>	
>	local DisplayAlerts
>	DisplayAlerts = ExcelSheet.Parent.Parent.DisplayAlerts
>	ExcelSheet.Parent.Parent.DisplayAlerts = FALSE
>	
>	=ExcelSheet.UsedRange.Replace(SearchFor, ReplaceWith, iif(MatchWholeWord, xlWhole, xlPart), xlByColumns, MatchCase)
>	
>	ExcelSheet.Parent.Parent.DisplayAlerts = DisplayAlerts
>endfunc
>*--------------------------------------------------------------------------
>
Dave
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform