BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Excel Worksheet selection

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Jesse
Guest





PostPosted: Wed Sep 28, 2005 8:23 pm    Post subject: Excel Worksheet selection Reply with quote



I have been using the following code to initiate WorkBook & Worksheet
variables:

WBk := Excel.Workbooks.Open(Filename, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, LCID);
WS := WBk.Worksheets.Item['Sheet1'] as _Worksheet;
WS.Activate(LCID);

This has been working great EXCEPT for when the user changes the name of the
first worksheet from 'Sheet1' to something else. So, I changed that line to
read:

WS := WBk.Worksheets[1] as _Worksheet;

This seems to work on my machine, running Excel 2000, and on several other
macines running Excel 2003, but on one machine it isn't working, and I
really don't understand why. Is there a better way to initiate the
Worksheet variable irregardless of the worksheet's name, other than what
I've used here?

Thanks,
Jesse


Back to top
Oliver Townshend
Guest





PostPosted: Wed Sep 28, 2005 11:02 pm    Post subject: Re: Excel Worksheet selection Reply with quote



Quote:
This seems to work on my machine, running Excel 2000, and on several other
macines running Excel 2003, but on one machine it isn't working, and I
really don't understand why. Is there a better way to initiate the
Worksheet variable irregardless of the worksheet's name, other than what
I've used here?

You can give the worksheet a name inside the VBA editor which the user can't
change (unless they go into the VBA editor as well).

You could also use the ActiveWorkSheet instead.

Oliver Townshend



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.