Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Excel automation: connecting to Excel

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jack - 20 Sep 2007 05:19 GMT
Which one is better (safer) way to do:

1.
   If moExcelApp.Workbooks.Count > 0 Then  'when any sheet is opened
       Set moExcelWS = moExcelApp.ActiveWorkbook.ActiveSheet
   End if

or

2.
   If moExcelApp.Workbooks.Count > 0 Then  'when any sheet is opened
       Set moExcelWS = moExcelApp.moExcelApp.Workbooks(1).Worksheets(1)
   End if

Jack
Tim Williams - 20 Sep 2007 07:12 GMT
They appear to do different things...
The first gets a reference to the activesheet, the second (ignoring the
duplicate app reference) gets a reference to the first sheet of the first
workbook.

Can you provide some context around what you want to do?

Tim

> Which one is better (safer) way to do:
>
[quoted text clipped - 11 lines]
>
> Jack
Jack - 20 Sep 2007 07:38 GMT
Thank you.
I need to connect my app to any Excel spreadsheet, which currently is
opened.
In the case if there are several spreadsheets opened, it does not matter
which one will be used.
Jack

> They appear to do different things...
> The first gets a reference to the activesheet, the second (ignoring the
[quoted text clipped - 20 lines]
>>
>> Jack
Tim Williams - 20 Sep 2007 17:41 GMT
Dave's post shows how.
Don't forget to check the typename of the sheet you get, in case it's a
chart and not a worksheet.

Tim

> Thank you.
> I need to connect my app to any Excel spreadsheet, which currently is
[quoted text clipped - 27 lines]
>>>
>>> Jack
Dave Peterson - 20 Sep 2007 13:26 GMT
If there are open workbooks, but all are hidden (no active sheet), then won't
both have trouble.

set moexcelws = nothing
on error resume next
Set moExcelWS = moExcelApp.ActiveWorkbook.ActiveSheet
on error goto 0

if moexcelws is nothing then
'failed
else
'worked
end if

> Which one is better (safer) way to do:
>
[quoted text clipped - 11 lines]
>
> Jack

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.