Solved

What workbook or worksheet has the focus?   vb6

Posted on 2004-09-25
2
773 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 34

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

809 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