Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What workbook or worksheet has the focus?   vb6

Posted on 2004-09-25
2
Medium Priority
?
780 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 1500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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

705 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