Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determine if worksheet already exists in Excel
Message
 
 
To
18/07/2005 17:28:18
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
01033660
Message ID:
01033666
Views:
22
This message has been marked as the solution to the initial question of the thread.
Hi Martha,

I don't know if there's a better way but you can loop through Sheets collection and compare the names
llFound = .F.
FOR i=1 TO oWorkbook.Sheets.Count
	IF UPPER(oWorkbook.Sheets.Item(i).Name) == UPPER("My Sheet Name")
		llFound = .T.
		EXIT
	ENDIF
ENDFOR

* Or using VFP8 and later
llFound = .T.
TRY
	oSheet = oWorkbook.Sheets.Item("My Sheet Name")
CATCH TO oExp WHEN oExp.ErrorNo = 1426 AND (UPPER("Invalid index") $ UPPER(oExp.Message))
	llFound = .F.
ENDTRY	
>
>I'm saving data off to an Excel file. As I do this I am creating a new worksheet and naming it based on a name the user supplies.
>
>IF the name of that worksheet already exists within that file I get a nasty little Excel generated message (very long and involved and probably not important if the following can be answered).
>
>Is there any way I can check to see if a worksheet with the same name already exists before I rename the new, blank worksheet created?
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform