Take the 2-minute tour ×

I've found a lot of other references to this error using Google but I'm having trouble making sense out of how they apply to what I'm doing.

Here's the VBA error I'm getting at compile time: "Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic."

VBA Code that causes the error:

'ftp is also a com object created in code not posted here
Dim f() As wooxter.FTPFile
f = ftp.GetFileList 'Returns an object array of type FTPFile
Dim i As Integer
For i = 1 To (UBound(f) - 1)
    If fFileExists(stg.LocalPicDir & "\" & f(i).FileName) = True Then
        If fGetFileSize(stg.LocalPicDir & "\" & f(i).FileName) = f(i).FileSize Then
        'Error occurs on the above line at compile time
            'The error occurs specifically on f(i).FileSize, but not on f(i).FileName
            'fGetFileSize returns a VBA Long. f(i).FileSize is a VB.NET Long
    End If
    End If

Here's my relevant .NET code:

Public Interface IFTPFile
    ReadOnly Property FileSize() As Long
    ReadOnly Property FileName() As String
End Interface

<ClassInterface(ClassInterfaceType.None)> _
Public Class FTPFile : Implements IFTPFile
    Private sFileName As String = ""
    Private lFileSize As Long

    Public Sub New(ByVal FName As String, ByVal FSize As Long)
        sFileName = FName
        lFileSize = FSize
    End Sub
End Class

'Fragment of a different class
Public Function GetFileList() As FTPFile() Implements IFTP.GetFileList
    Dim ftpfiles() As EnterpriseDT.Net.Ftp.FTPFile
    ftpfiles = fCon.GetFileInfos
    Dim result(ftpfiles.Length - 1) As FTPFile
    For i As Integer = 0 To ftpfiles.Length - 1
        result(i) = New FTPFile(ftpfiles(i).Name, ftpfiles(i).Size)
    Return result
End Function
share|improve this question

1 Answer 1

up vote 1 down vote accepted

COM has no notion of constructors. Or more to the point, constructors with arguments. If you declare any constructors for your class then it must include a parameterless constructor. The one that the client code will always use. You'll need to make FileName and FileSize properties.

The next problem is that VBA doesn't have a 64-bit integral data type. Change the FileSize property from Long to, say, Integer or Double. Avoid Single, it doesn't have enough significant digits to accurately store a file size. It cannot store 16777217.

share|improve this answer
As near as I can tell my VBA code should never fire the class constructor. Also, I changed my code so it doesn't use anything but an empty constructor and I'm still getting the same error message at the same place. –  HK1 Mar 28 '11 at 18:39
There's another problem, VBA doesn't have a native 64-bit integral type. Check what happens when you redefine FileSize as an Integer or Double. –  Hans Passant Mar 28 '11 at 18:45
Your comment on the data type was the answer to the problem. In fact, I'm using the constructor just as I listed above since my code in VBA will never initialize the constructor. The only difference is I've changed FileSize to Single. Care to edit your answer? I'm not saying that your current answer is wrong information, only that it's not the answer to the problem I was having. –  HK1 Mar 28 '11 at 19:00
Post updated, don't use Single. –  Hans Passant Mar 28 '11 at 19:03

Your Answer


