Solved

Excel VBA: Finding workbook form belongs to

Posted on 2012-04-11
1
321 Views
Last Modified: 2012-04-11
What VBA code would I need so that when a form in Excel opens, the workbook the form belongs to is stored in a public variable.

e.g., Whenever "ctrl+Y" is pressed the form opens. Therefore if the user is on another workbook and presses "ctrl-y" I would like the form to log the workbook the form belongs to, NOT THE CURRENT workbook.

e.g., putting "activeworkbook.name" in the "On Form Open" sub would not work in this case, as the form could be opened while the user is on another workbook in such case would yield incorrect results.
0
Comment
Question by:ouestque
[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
1 Comment
 
LVL 24

Accepted Solution

by:
StephenJR earned 500 total points
ID: 37832599
You can use ThisWorkbook to refer to the book containing code.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

724 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