Solved

What workbook or worksheet has the focus?   vb6

Posted on 2004-09-25
2
766 Views
Last Modified: 2006-11-17
I have few workbooks open.  User may click on any of the workbooks or worksheets.  I have a time event, and in it, I would like to findout what is worksheet name and the full path of the workbook.  I guess us of GetObject is out of question becuse the process is in reverse in this case.

This code is excel version, I need to change it to work in vb environment:

Dim ws As Worksheet
Dim wbbk As Workbook
Set ws=ActiveSheet        '<--  I am getting error here,
Set wbbk=ActiveWorkbook
MsgBox  wb.Path & ", " & ws.Name

If I use GetObject, I need to supply the name of workbook and it will then send the focus to the supplied workbook not the one which had the focus (was active).

I hope it is clear what I am looking for.

Thanks.
0
Comment
Question by:Mike Eghtebas
2 Comments
 
LVL 4

Accepted Solution

by:
Rick_Townsend earned 500 total points
ID: 12152723
I think I've used that syntax before without problems, but if you're having problems you can try getting the active sheet from the active workbook.

Dim ws As Worksheet
Dim wbbk As Workbook
Set wbbk=ActiveWorkbook
Set ws=ActiveWorkbook.ActiveSheet
MsgBox  wb.Path & ", " & ws.Name
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 12152893
Dim ws As Excel.Worksheet       'I had missed Excel. before
Dim wbbk As Excel.Workbook
Dim xlApp As Excel.Application    ' added xlApp
Set xlApp = GetObject(,"Excel.Application")        '<-- this has to be included
Set wbbk=xlApp.ActiveWorkbook
Set ws=wbbk.ActiveSheet
MsgBox  wb.Path & ", " & ws.Name

Now, works fine.  I was thinking GetObject will open a new instance of ecxel and I was wrong.

Mike
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Share codes 68 115
Window placement 17 65
Concatenate 2 userform comboboxes to a userform text box 4 49
Put text in a picture ASP.NET C# 2 37
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now