Solved

Excel workbook referencing error: VBA VB

Posted on 2010-08-18
10
565 Views
Last Modified: 2012-05-10
Hi,

I have two macros in excel vba.  One reference the other to crate dynamic menus (i.e.: the macro that creates the menu has permission for access to VBA Project).  We intermittently get the message "This workbook is currently referenced by another workbook and cannot be closed when excel is started.  Once it occurs, it stays.

I have included "On error resume next" and "applications.displayalerts = false" code in auto_open in both macros.  All seems fine until windows performs an update.  I do not know if the update has anything to do with this , but it seems to possibly have some correlation.

I can resolve the issue by re-establishing the reference between the macros.  However the macros are deployed as packages to customers in large enterprises and therefore that manual solution is not feasible..

Any idea as to how to prevent this message from showing -- permantly?

Thanks
0
Comment
Question by:damoruso
  • 5
  • 4
10 Comments
 
LVL 11

Expert Comment

by:jkpieterse
ID: 33472605
Seems you have two workbooks, one referencing the other and the "other" workbook is closed first
(which -because it is referenced by another workbook open in Excel- causes the warning message to occur).

You could work around it, but the method depends on your code: why the reference?
0
 

Author Comment

by:damoruso
ID: 33475338
This occurs when Excek opens (even if no macros run).

The reason why they are separate is that main macro is password protected and the dynamic menu generator macro doesn't run if it protected.  So we extracted the snippet of code that generates the menu and put it into a separate unprotected macro.  The main macro refers to the menu generator. BTW: the dynamic menu code generates VBA on the fly and accesses VBA Project.

If there is a way that the menu code can work from within the password protected main macro, that would be ideal.
0
 
LVL 11

Expert Comment

by:jkpieterse
ID: 33483543
I would use a table driven approach to generate the menu. Search the web for "table driven commandbar excel" and you should find examples. I think John Walkenbach has an example somewhere on his site.
0
 

Author Comment

by:damoruso
ID: 33484619
Sorry. I mis-wrote.  These are actually forms that are being generated, not menus.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Expert Comment

by:jkpieterse
ID: 33485364
You don't have to actually generate a form in the VBA project, you can also populate an existing userform object with controls at runtime. That way, you also do not need to allow access to the VBProject. It does require you to use a class module to catch the events of the controls which were added at runtime however.
0
 

Author Comment

by:damoruso
ID: 33485679
That would be great.  So I will be able to dynamically add rows of textboxes and checkbox controls based on the amount of data I have?
0
 
LVL 11

Accepted Solution

by:
jkpieterse earned 500 total points
ID: 33491258
Exactly.
I have an example project that does something like this. It includes a database file which goes in the same folder as the excel file.
TableDrivenForm002.zip
0
 

Author Comment

by:damoruso
ID: 33497810
This looks good. I'm going through it now.  It seems as though udDataEntry is of most interest for me.  I'll keep you posted.  Thanks!
0
 

Author Closing Comment

by:damoruso
ID: 33664155
Great.  Thanks!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ms sql stored procedure 22 77
Mac-based software for Excel 8 20
Importing csv to excel - text formating 14 21
Macro 3 19
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now