Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default opening diff. worksheets in opened workbook

How could I open another spreadsheet in the same workbook
if the workbook has been already opened?
I'm doing it from MS Access.

If logWorkbookIsOpened = False Then
'it's working good
Set xlBook = xlApp.Workbooks.Open(strWorkbookName)
Set xlSheet = xlBook.Worksheets(strWorksheetName)
xlSheet.Activate

xlApp.Visible = True

Else
'here is a mistake #0
Set xlSheet = Workbooks(strWorkbookName).Worksheets
(strWorksheetName)
xlSheet.Activate
xlApp.Visible = True

End If

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default opening diff. worksheets in opened workbook

from your main access vba call a sub that assigns the
workbook to a variable - assumes the workbook is open. If
its not then it would raise an error...that's trapped by
testing the err number , a non-zero value is an
error...in which case it then opes the book...either way,
it returns the workbook object assigned tot hat workbook
to the calling code


dim wb as workbook
Set WB = GetWorkbook("MyBook")
if WB Is Nothing then
msgbox "Cannot find " & "MyBook"
exit sub
end if
.... workbook assigned to wb, carry on...
.... your access code



Private Function GetWorkbook(sName as string) as workbook
on error resume next
dim wb as workbook
set wb = xlApp.Workbooks(sName)
if err.number<0 then
err.clear
set wb = xlApp.Workbooks.Open(sName)
end if
set GetWorkbook = wb
End Function


HTH

Patrick Molloy
Microsoft Excel MVP

-----Original Message-----
How could I open another spreadsheet in the same

workbook
if the workbook has been already opened?
I'm doing it from MS Access.

If logWorkbookIsOpened = False Then
'it's working good
Set xlBook = xlApp.Workbooks.Open(strWorkbookName)
Set xlSheet = xlBook.Worksheets(strWorksheetName)
xlSheet.Activate

xlApp.Visible = True

Else
'here is a mistake #0
Set xlSheet = Workbooks(strWorkbookName).Worksheets
(strWorksheetName)
xlSheet.Activate
xlApp.Visible = True

End If

Thanks

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default opening diff. worksheets in opened workbook

Set xlBook = xlApp.Workbooks.Open(strWorkbookName)
Set xlSheet 1= xlBook.Worksheets(strWorksheetName1)
Set xlSheet 2= xlBook.Worksheets(strWorksheetName2)



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"AlexD" wrote in message
...
How could I open another spreadsheet in the same workbook
if the workbook has been already opened?
I'm doing it from MS Access.

If logWorkbookIsOpened = False Then
'it's working good
Set xlBook = xlApp.Workbooks.Open(strWorkbookName)
Set xlSheet = xlBook.Worksheets(strWorksheetName)
xlSheet.Activate

xlApp.Visible = True

Else
'here is a mistake #0
Set xlSheet = Workbooks(strWorkbookName).Worksheets
(strWorksheetName)
xlSheet.Activate
xlApp.Visible = True

End If

Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default opening diff. worksheets in opened workbook

Thanks a lot.

But, if user press a button on some form to open the
workbook with a spreadsheet1 and didn't close the workbook
and wants to open another spreadsheet2 in the same
workbook by pressing the button the procedure will open
another instance of workbook with the spredshhet2. My
question is how to avoid openning the second and so on
workbooks if we just need to open another spreadsheet.

Regards,

Alex
-----Original Message-----
from your main access vba call a sub that assigns the
workbook to a variable - assumes the workbook is open. If
its not then it would raise an error...that's trapped by
testing the err number , a non-zero value is an
error...in which case it then opes the book...either way,
it returns the workbook object assigned tot hat workbook
to the calling code


dim wb as workbook
Set WB = GetWorkbook("MyBook")
if WB Is Nothing then
msgbox "Cannot find " & "MyBook"
exit sub
end if
.... workbook assigned to wb, carry on...
.... your access code



Private Function GetWorkbook(sName as string) as workbook
on error resume next
dim wb as workbook
set wb = xlApp.Workbooks(sName)
if err.number<0 then
err.clear
set wb = xlApp.Workbooks.Open(sName)
end if
set GetWorkbook = wb
End Function


HTH

Patrick Molloy
Microsoft Excel MVP

-----Original Message-----
How could I open another spreadsheet in the same

workbook
if the workbook has been already opened?
I'm doing it from MS Access.

If logWorkbookIsOpened = False Then
'it's working good
Set xlBook = xlApp.Workbooks.Open(strWorkbookName)
Set xlSheet = xlBook.Worksheets(strWorksheetName)
xlSheet.Activate

xlApp.Visible = True

Else
'here is a mistake #0
Set xlSheet = Workbooks(strWorkbookName).Worksheets
(strWorksheetName)
xlSheet.Activate
xlApp.Visible = True

End If

Thanks

.

.

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
Need to print a workbook but worksheets have diff print areas Angela Steele Excel Discussion (Misc queries) 1 January 17th 08 07:39 PM
Is there away to keep Excel from opening a copy of an already opened workbook and the pages not be at 100% but Marc New Users to Excel 1 March 13th 06 01:51 PM
Count If 2 Diff Values Appear on Several Worksheets w/in Workbook Kat Excel Worksheet Functions 5 September 22nd 05 06:44 PM
Slow opening Excel Workbook with over 50 Worksheets KathyRice Excel Discussion (Misc queries) 1 January 4th 05 11:49 PM
Is it possible to require that a KEY NUMBER be imputed in a workbook 1 before workbook 2 can be opened? Marcello do Guzman Excel Programming 0 October 15th 03 06:29 PM


All times are GMT +1. The time now is 05:31 AM.

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

About Us

"It's about Microsoft Excel"