简体   繁体   中英

VBA user defined type not defined (only sometimes)

In my Excel Workbook sometimes I get the following error:

vba user defined type not defined

I do know that this typically means that there is some type in the code excel(VBA) does not know .

The strange thing is that the code runs perfectly fine and this doesn't happen while compiling.

This error randomly occures sometimes at all methods of the Application.Calculate family and on F9 keypress. Not always but sometimes.

The same behavior has a vbe error message with this description:

visual basic module contains a syntax error

When I click debug it lands on application.calculate(full) and if I continue the code (with F5) it continues without errors.

EDIT: Sometimes when I copy this function to another workbook it gets affected by the Userdefined type error:

Option Explicit

Public Function MergeAreaValue(rng As Range) As String
On Error Resume Next

If rng.MergeCells = True Then
    MergeAreaValue = rng.MergeArea.Cells(1).Value2
Else
    MergeAreaValue = rng.Value2
End If

End Function

The function gets the value from a merged area.

EDIT2: I've the userdefined type error always occures at calculation but doesn't break it. The workbook still calculates normal .. the message is just annoying.

It seems me that "sometimes" is the keyword. Try to decompile file. With this , for example.

Many years I use it without any problems, but with benefits only :) Excel have no internal decompiler as Access /decompile. Don't forget to backup by yourself, not the tool only :) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM