XLAddSheet

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
hoangvo81
Pro Scripter
Posts: 69
Joined: Tue Feb 07, 2012 8:02 pm

XLAddSheet

Post by hoangvo81 » Tue Oct 09, 2012 9:11 pm

Hi,

Just wondering if anyone has any suggestion (aside from vbscript).
Is there any way to check if an excel Tab exist before trying to create it?

XLAddSheet takes 2 parameters, the handle and the name.
if I blindly add the name, and the name of the tab exist, it will create a new sheet called "Sheet#" where # is the next number if you have tabs (sheet1, sheet2, sheet3 - in which case # would be 4).

It would defintely be beneficial if trying to add a sheet and the sheet exist, that it does nto add and just return an error code or something, then we can check the return result and decide what to do. and if it doesnt exist the name of the tab is added and the result is successful.

Any suggestion is appreciated.

Thanks,

Hoang

PS. I can go through VBScript, but if I can do it in one swoop through Macroscheduler I rather take that route.

User avatar
Marcus Tettmar
Site Admin
Posts: 7393
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Oct 11, 2012 7:49 pm

Right now I think you'd need to do it with VBScript.

The only other workaround I can think of would be to try to query or set a value from the sheet first using XLGetCell/XLSetCell and check for an error which you'd get if the sheet didn't already exist. And if so, use XLAddSheet to add it.

Haven't tried this .. just an idea.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

hoangvo81
Pro Scripter
Posts: 69
Joined: Tue Feb 07, 2012 8:02 pm

Post by hoangvo81 » Mon Oct 15, 2012 2:48 pm

Thanks Marcus,

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts