Simplest way to determine if a sheet exists

[ Edited ]

I am writing a function that will replace the background on a sheet with a sheet from another file.  The input parameters include the sheetnames of the source and target.


What is the simplest way to determine if a sheet exists in a Draft file?


I know I could loop through the sheets collection and return a  boolean if I do find it.  But is there a way to try accessing the sheet by name and just see if an exception comes back?

Dim sourceBackground As SolidEdgeDraft.Sheet 
sourceBackground = oSourceDoc.Sheets.Item(sourceSheetName)

What exception would be thrown in this case if the sheet does not exist?



Carl Breving


Re: Simplest way to determine if a sheet exists

You are correct Carl. Most if not all Item() methods allow you to pass in a VARIANT (Object). Typically, they're looking for an Integer to specify an index or String to specify a key. I believe in the case of Sheets, each sheet name is used as the key. Regarding which exception is thrown, I believe it's something along of the lines of invalid index.

Jason Newell
Applications Architect