Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Excel automation: connecting to Excel

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Excel automation: connecting to Excel

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


"Jack" <replyto@it wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Excel automation: connecting to Excel

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

"Tim Williams" <timjwilliams at gmail dot com wrote in message
...
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


"Jack" <replyto@it wrote in message
...
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Excel automation: connecting to Excel

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



Jack wrote:

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


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Excel automation: connecting to Excel

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


"Jack" <replyto@it wrote in message
...
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

"Tim Williams" <timjwilliams at gmail dot com wrote in message
...
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


"Jack" <replyto@it wrote in message
...
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







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
connecting wordpad and excel Jan Excel Discussion (Misc queries) 1 May 4th 07 01:37 PM
Connecting excel to the weblink Igneshwara reddy[_2_] Excel Programming 4 March 6th 07 10:39 PM
EXCEL-VBA, ADO not connecting to a TXT file coco Excel Programming 1 June 17th 05 04:59 AM
Excel connecting to Teradata Bill Excel Programming 3 March 31st 05 08:47 PM
Connecting to SQL from Excel Keith La Force Excel Programming 4 March 2nd 05 09:27 PM


All times are GMT +1. The time now is 01:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"