Solved

What workbook or worksheet has the focus?   vb6

Posted on 2004-09-25
2
774 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
[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
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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

756 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