Solved

What workbook or worksheet has the focus?   vb6

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

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.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 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…
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…
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

617 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