Mike Eghtebas
asked on
What workbook or worksheet has the focus? vb6
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dim wbbk As Excel.Workbook
Dim xlApp As Excel.Application ' added xlApp
Set xlApp = GetObject(,"Excel.Applicat
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