?
Solved

OPen a Specific Excel sheet from a VB Button.

Posted on 2004-09-08
8
Medium Priority
?
173 Views
Last Modified: 2010-05-02
OK, I can open an Excel Spreadsheet from a button, but how do I open a specific sheet inside the Excel Workbook.

Here is the code to open an excel Workbook:

Set ExcelWBk = Excel.Workbooks.Open("H:\Comets Portland\Comets\Excel\Queue Age\que aging" )

How would I make it open a worksheet name "HB PRIME"?
0
Comment
Question by:spzbiegien
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 12011548
This works for me.

ExcelWbk.Sheets("SheetName").Activate
0
 

Author Comment

by:spzbiegien
ID: 12011788
It doesn't work for me!  Where would you add the code to make it work.  See Code Below!


Private Sub CmdQuarter3_Click()
Dim Excel As Excel.Application
Dim ExcelWBk As Excel.Workbook
Dim ExcelWS As Excel.Worksheet

           
            Form1.Animation1.Open "H:\Comets Portland\Comets\comtest2.avi"
            Form1.Animation1.Visible = True
            Set Excel = CreateObject("Excel.Application")
            With Excel
                .Visible = True
            End With
           
            Set ExcelWBk = Excel.Workbooks.Open("H:\Comets Portland\COMETS\Excel\CometsForecasts\Q3 2004")
            Set ExcelWS = Excel.Sheets("CIB Forcast").Activate
            Form1.Animation1.Visible = False
            Exit Sub
 
End Sub
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12011854
Two problems.  First, use the workbook object, not the Excel object.  Second, don't use Set on the command to activate a sheet.  In the code above replace

    Set ExcelWS = Excel.Sheets("CIB Forcast").Activate

with

    ExcelWBk.Sheets("CIB Forcast").Activate
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:spzbiegien
ID: 12011917
i GET RUN TIME ERROR "9" SUBSCRIPT OUT OF RANGE
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12011952
That sounds to me as if the sheet name isn't correct.  I created a workbook here and added a sheet with the name "CIB Forcast" and tested the code.  It worked fine.
0
 

Author Comment

by:spzbiegien
ID: 12011963
Thank you,  I Spelled Forecast wrong!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12011986
No problem, I do things like that all the time.
0
 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 1500 total points
ID: 12012866
Private Sub CmdQuarter3_Click()

         Dim XlObj As Excel.Application                '<-- note XlObj in place of Excel
         Dim ExcelWBk As Excel.Workbook
         Dim ExcelWS As Excel.Worksheet

           
            Form1.Animation1.Open "H:\Comets Portland\Comets\comtest2.avi"
            Form1.Animation1.Visible = True
            Set XlObj = GetObject(,"Excel.Application")      
            XlObj .Visible = True
           
            Set ExcelWBk = XlObj .Workbooks.Open("H:\Comets Portland\COMETS\Excel\CometsForecasts\Q3 2004")
            Set ExcelWS = XlObj.Worksheets("CIB Forcast")
            ExcelWS.Activate
            Form1.Animation1.Visible = False
 
End Sub
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question