activating diff. worksheets in opened workbook

A

AlexD

How could I open another spreadsheet in the same workbook
if the workbook has been already opened?
If logWorkbookIsOpend = False Then

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
 
L

Larry Linson

This newsgroup is devoted to Microsoft Access database software. You need to
ask your question in a newsgroup devoted to Microsoft Excel spreadsheet
software. Look for one at "news.microsoft.com".
 
T

TC

I know that but I'm doing everything from MS Access database.

Sure - but you don't know what command to issue, unless you know the Excel
event model. People writing in Access VBA, do not necessarily know the Excel
event model. That's why Larry suggested asking in an Excel group. The answer
will come from an Excel user - not an Access user.

However, I imagine (as a guess) that you would use the Add method of the
Worksheets collection:

dim xlNewSheet as (whatever)
set xlNewSheet = xlBook.Worksheets.Add "new sheet name"

HTH,
TC
 
T

Tim Ferguson

How could I open another spreadsheet in the same workbook
if the workbook has been already opened?

TC is right: this is an excel programming question.

Nevertheless, the answer is that you cannot "open" a sheet in a workbook.
All the sheets are as open as the book itself.

At a guess, you probably want to create a Range object and set it to some
area on the workbook in question:

'select the top five rows and left five columns
With xlBook.Worksheets("Sheet2)
Set rng= .Range(.Cells(1,1), .Cells(5,12))

End With

' clear out all the old data
rng.Clear

' etc

It is easier to learn, develop, and debug Excel programs within Excel
itself, then transport the code to a foreign app and add the OLE automation
stuff.

B Wishes


Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top