INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Excel VBA Troubleshooting Question

Excel VBA Troubleshooting Question

(OP)
We have an Excel VBA application that has a custom button on it for users to add a new worksheet to their workbook. One workbook shows this error message when the new worksheet button is clicked: "Compile error: sub or function not defined".

Code is displayed, shown below. I am looking for ideas as to what in this workbook is causing the add worksheet button to fail. Does the error message and the code excerpt offer any clues as to where the problem lies? I am more of an end user, not a programmer, so any advice on what Excel is trying to tell me would be appreciated.

The button works fine on new workbooks or other existing workbooks. It is just this one workbook where it is failing.

RE: Excel VBA Troubleshooting Question

Steve,

On that machine is that highlighted function in a module as a function procedure? Or if in another application, has that application been referenced?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Excel VBA Troubleshooting Question

(OP)
It is listed under Excel Objects. Here is a screenshot

RE: Excel VBA Troubleshooting Question

That's where the function is CALLED.

Where is the function code?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Excel VBA Troubleshooting Question

(OP)
Now I understand what you are looking for. I will dig into the application to locate it. Maybe it is part of the customized ribbon. Anyway, I will look for it and see what turns up. Thanks for your help.

RE: Excel VBA Troubleshooting Question

In your VBA editor Edit > Find in VBA Project.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Excel VBA Troubleshooting Question

(OP)
Would this be it?

Public Sub CBK_SetTabsVisible(ByVal isAsst As Boolean)
If showXlTabs Then 'Exit Sub 'if XL tabs are visible then asst tabs and summ tab are hidden so do nothing, otherwise set tabs for asst or summ per isAsst
showAsstTabs = False
showSummTab = False
Else
showAsstTabs = isAsst
showSummTab = Not isAsst
End If
If (AP_Ribbon Is Nothing) Then Set AP_Ribbon = GetRibbon(CLng(ActiveWorkbook.CustomDocumentProperties("UI_Pointer"))) 'If ribbon pointer lost, reset it
AP_Ribbon.InvalidateControl "tabAsst"
AP_Ribbon.InvalidateControl "tabView"
AP_Ribbon.InvalidateControl "tabProfile"
AP_Ribbon.InvalidateControl "tabOptions"
AP_Ribbon.InvalidateControl "tabSummary"

AP_Ribbon.InvalidateControl "tabXLHome"
AP_Ribbon.InvalidateControl "tabXLView"

End Sub

RE: Excel VBA Troubleshooting Question

In what code object did you find this function?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Excel VBA Troubleshooting Question

(OP)
It is in a module called UI

RE: Excel VBA Troubleshooting Question

Can't see the problem.

But you should have Option Explicit at the top of every code module!

Tools > Editor...and check Require Variable Declaration in your VBA Editor will prevent something like this from occurring in the future.

This will prevent you from getting this far into a Project with undeclared or illegal variables.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Excel VBA Troubleshooting Question

(OP)
OK. Thanks for taking a look at this.

RE: Excel VBA Troubleshooting Question

Looks like the AP9.xlam is an excel add-in and the ASST sheet is a template that fires code (Worksheet_Activate) when it is copied to new workbook. The new workbook's VBA project is referenced to VBA project of the add-in, so macros in new workbook that use add-in's macros can be executed.
I guess that the error is in another workbook, other than in your first image. If so check references (Tools>References), among other checked you may see MISSING. In this case excel can't see the add-in in expected location.
If the error is in the add-in, check the referencess too, VBA reports random errors in such case.

combo

RE: Excel VBA Troubleshooting Question

(OP)
Combo

Thanks for your suggestion - references were the problem. The developer had created a custom AP9 reference that the user had somehow unchecked (shown highlighted below). Once that was checked, the issue was resolved. The references checkbox is not something the everyday user would stumble across, so I am surprised this problem occurred in the first place. Anyway, thanks very much for your advice.

RE: Excel VBA Troubleshooting Question

Kc27, don't forget to give combo a star. Helps other members looking for good tips.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Excel VBA Troubleshooting Question

(OP)
Done, thanks for the heads up about marking the post.

RE: Excel VBA Troubleshooting Question

(OP)
Selecting the unchecked reference fixed the problem, but the change is not permanent, even after the file is saved. Here is what I do now:

1. Open the VB Editor,
2. Go to Tools > Refernces
3. Click the checkbox for the reference,
4. Click the save button.
5. Close the code editor,
6. Save and close the Excel file.

The next time the file is opened, the checkbox will have reverted back to being unchecked. How do save the file so that the checked reference is permanently selected?

RE: Excel VBA Troubleshooting Question

Does it happen on the same computer (i.e. open, change references and save, open again)? Excel stores full path to referenced workbook, you may loose reference when the full path to the add-in is different to stored one.

combo

RE: Excel VBA Troubleshooting Question

(OP)
Yes, the reselecting of the reference, saving of the file, closing of the file, and then reopening of the file (with the reference somehow reverted back to unchecked) is all done on the same computer.

RE: Excel VBA Troubleshooting Question

I did a quick test with two regular workbooks, vba project in one of them (File1) references vba project of the second File2. The second vba project was renamed to have unique name.
Observations:
1) both files closed, I open File1: File2 opens automatically,
2) File2 moved to other location, I open File1: no warning, missing reference to File2 (MISSING:File2.xlsm). No File2 in avalilable references, however I can point to File2, excel opens the file and reference is fixed. I can save File1, when I reopen it, it points to proper location of File2,
3) File2 moved to other location, I open File2 and next File1: references are ok.

In your case first I would check If I saved proper file. Next, as AP9.xlam is (or, at least should be) an add-in, I would check if it is installed (options -> excel add-ins), in this case it is opened and closed with excel, you shouldn't have problems with referencing it.

combo

RE: Excel VBA Troubleshooting Question

(OP)
Thanks for the suggestions. I checked the time stamp on the Excel file that I had saved, and showed the correct "last saved" time. I also verified that AP9.xlam is an add-in.

Somehow the user has done something to the file where the reference selection is not retained. I know this because I started a new sheet, and am able to select or deselect the AP9Code reference, save and have the selection or deselection retained.

RE: Excel VBA Troubleshooting Question

If your application has no VBA code in it itself then it doesn't remember any references that you add to it. Solution is to add any VBA you like to your application, e.g. an empty sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close