Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA Troubleshooting Question 1

Status
Not open for further replies.

kc27

Technical User
Sep 10, 2008
171
US
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.

ap9error_t8ljat.gif
 
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,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
It is listed under Excel Objects. Here is a screenshot

ap9excelobjects_dhzik2.gif
 
That's where the function is CALLED.

Where is the function code?

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
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.
 
In your VBA editor Edit > Find in VBA Project.

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
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
 
In what code object did you find this function?

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
It is in a module called UI

ap9_ui_module2_dkqcy1.gif
 
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,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
OK. Thanks for taking a look at this.

 
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
 
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.

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

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
Done, thanks for the heads up about marking the post.
 
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?
 
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
 
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.
 
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
 
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.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top