Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Need to print a workbook but worksheets have diff print areas | Excel Discussion (Misc queries) | |||
Is there away to keep Excel from opening a copy of an already opened workbook and the pages not be at 100% but | New Users to Excel | |||
Count If 2 Diff Values Appear on Several Worksheets w/in Workbook | Excel Worksheet Functions | |||
Slow opening Excel Workbook with over 50 Worksheets | Excel Discussion (Misc queries) | |||
Is it possible to require that a KEY NUMBER be imputed in a workbook 1 before workbook 2 can be opened? | Excel Programming |