Error when calling vb dll subroutine from excel vba

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Blaine

    Error when calling vb dll subroutine from excel vba

    I've created the following dll in vb 2008.
    _______________ _______________ _______________ ______________
    Public Interface IDemo
    Sub doSomething()
    End Interface
    Public Class implementIDemo
    Implements IDemo
    Dim varAsInterface As IDemo = New implementIDemo( )
    Dim varAsClass As implementIDemo = New implementIDemo( )
    Private Sub doSomething() Implements IDemo.doSomethi ng
    MsgBox("Hello")
    End Sub
    End Class
    _______________ _______________ _______________ ______________
    I then used tlbexp.exe, gacutil.exe, regasm,exe, and sn.exe so that the
    "doSomethin g" sub routine could be accessed/called from an excel vba (by
    first referencing the tlb file).

    My excel vba is as follows:

    _______________ _______________ _______________ ______________
    Private moTemp As mydll.IDemo

    Sub trial()
    moTemp.doSometh ing
    End Sub
    _______________ _______________ _______________ ______________

    Excel VBA seems to recognize class and subfunction as I'm typing them,
    but when I run the "trial" macro I get the following error:

    "Run-time error '91': Object variable or With block variable not set"

    Any ideas?

    Thanks in advance,

    *** Sent via Developersdex http://www.developersdex.com ***
  • =?Utf-8?B?S2VycnkgTW9vcm1hbg==?=

    #2
    RE: Error when calling vb dll subroutine from excel vba

    Blaine,

    I don't program in vba, but shouldn't it be:

    Private moTemp As NEW mydll.IDemo

    Or at least whatever facility vba has for creating a new instance?

    Kerry Moorman


    "Blaine" wrote:
    I've created the following dll in vb 2008.
    _______________ _______________ _______________ ______________
    Public Interface IDemo
    Sub doSomething()
    End Interface
    Public Class implementIDemo
    Implements IDemo
    Dim varAsInterface As IDemo = New implementIDemo( )
    Dim varAsClass As implementIDemo = New implementIDemo( )
    Private Sub doSomething() Implements IDemo.doSomethi ng
    MsgBox("Hello")
    End Sub
    End Class
    _______________ _______________ _______________ ______________
    I then used tlbexp.exe, gacutil.exe, regasm,exe, and sn.exe so that the
    "doSomethin g" sub routine could be accessed/called from an excel vba (by
    first referencing the tlb file).
    >
    My excel vba is as follows:
    >
    _______________ _______________ _______________ ______________
    Private moTemp As mydll.IDemo
    >
    Sub trial()
    moTemp.doSometh ing
    End Sub
    _______________ _______________ _______________ ______________
    >
    Excel VBA seems to recognize class and subfunction as I'm typing them,
    but when I run the "trial" macro I get the following error:
    >
    "Run-time error '91': Object variable or With block variable not set"
    >
    Any ideas?
    >
    Thanks in advance,
    >
    *** Sent via Developersdex http://www.developersdex.com ***
    >

    Comment

    • Blaine

      #3
      RE: Error when calling vb dll subroutine from excel vba

      Thanks for the reply Kerry.

      When I use "Private moTemp As NEW mydll.IDemo" it produces the error
      "Invalid use of NEW keyword"


      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      • =?Utf-8?B?S2VycnkgTW9vcm1hbg==?=

        #4
        RE: Error when calling vb dll subroutine from excel vba

        Blaine,

        Maybe the syntax is:

        Private moTemp As mydll.IDemo

        Sub trial()
        Set moTemp = New mydll.IDemo
        moTemp.doSometh ing
        End Sub

        Kerry Moorman


        "Blaine" wrote:
        Thanks for the reply Kerry.
        >
        When I use "Private moTemp As NEW mydll.IDemo" it produces the error
        "Invalid use of NEW keyword"
        >
        >
        *** Sent via Developersdex http://www.developersdex.com ***
        >

        Comment

        • Blaine

          #5
          RE: Error when calling vb dll subroutine from excel vba


          Kerry,

          I'm still getting the "Invalid use of NEW keyword" error.

          Thanks


          *** Sent via Developersdex http://www.developersdex.com ***

          Comment

          • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

            #6
            RE: Error when calling vb dll subroutine from excel vba

            Shouldn't it be "new implimentIDemo" ? Your IDemo is an interface, so you
            have to create an actual class instance and cast it.

            "Blaine" wrote:
            >
            Kerry,
            >
            I'm still getting the "Invalid use of NEW keyword" error.
            >
            Thanks
            >
            >
            *** Sent via Developersdex http://www.developersdex.com ***
            >

            Comment

            • kimiraikkonen

              #7
              Re: Error when calling vb dll subroutine from excel vba

              On Aug 6, 9:11 pm, Blaine <anonym...@devd ex.comwrote:
              Kerry,
              >
              I'm still getting the "Invalid use of NEW keyword" error.
              >
              Thanks
              >
              *** Sent via Developersdexht tp://www.developersd ex.com***
              Hi,
              My guess would be that one or more of your references may be missing.
              Make sure you added proper reference to your class library in solution
              explorer by clicking "show all files" and expand "references ".

              BTW, are you using VB6 or lower,... or VB.NET? Because when you have a
              missing reference the error message would be "Type '<typename>' is not
              defined" on .NET.

              Hope this helps,

              Onur Güzel

              Comment

              • Blaine

                #8
                RE: Error when calling vb dll subroutine from excel vba


                Mike,

                I tried:

                Dim motemp As mydll.IDemo

                Sub trial()

                Set motemp = New mydll.implement IDemo
                motemp.doSometh ing

                End Sub

                is this what you were thinking? It's giving the following error:
                "File or assembly name mydll, or one of its dependencies, was not
                found."

                Thanks,


                *** Sent via Developersdex http://www.developersdex.com ***

                Comment

                • Blaine

                  #9
                  Re: Error when calling vb dll subroutine from excel vba


                  Hello Onur,

                  I am using vb 2008 express edition (it's the only thing that I have
                  access to).

                  Thanks


                  *** Sent via Developersdex http://www.developersdex.com ***

                  Comment

                  • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

                    #10
                    RE: Error when calling vb dll subroutine from excel vba

                    Yes, that is what I had wanted you to try, but I don't know why the variable
                    motemp is declared outside the sub. As to the missing dependency, you should
                    look at Depends.exe that comes with visual studio. I think it may come with
                    express, but I'm not positive. It should tell you about missing dependencies
                    from the dll or exe.


                    "Blaine" wrote:
                    >
                    Mike,
                    >
                    I tried:
                    >
                    Dim motemp As mydll.IDemo
                    >
                    Sub trial()
                    >
                    Set motemp = New mydll.implement IDemo
                    motemp.doSometh ing
                    >
                    End Sub
                    >
                    is this what you were thinking? It's giving the following error:
                    "File or assembly name mydll, or one of its dependencies, was not
                    found."
                    >
                    Thanks,
                    >
                    >
                    *** Sent via Developersdex http://www.developersdex.com ***
                    >

                    Comment

                    • Blaine

                      #11
                      RE: Error when calling vb dll subroutine from excel vba


                      Mike,

                      I think you may be on to something. I ran the "Depends.ex e", as you
                      suggested, and it gave me the following warnings about my dll:

                      1.)Warning: At least one delay-load dependency module was not found.

                      2.)Warning: At least one module has an unresolved import due to a
                      missing export function in a delay-load dependent module.

                      Also it said there was an error opening file "DWMAPI.DLL ", the system
                      cannot find the file specified.

                      How do I add or fix this?

                      Thanks!


                      *** Sent via Developersdex http://www.developersdex.com ***

                      Comment

                      • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

                        #12
                        RE: Error when calling vb dll subroutine from excel vba

                        Take a look at this site: http://dependencywalker.com/faq.html.

                        It looks like you have some depenency on IE 7 perhaps.

                        DWMAPI.dll is a Vista dll, to my knowledge. Are you running on Vista?


                        "Blaine" wrote:
                        >
                        Mike,
                        >
                        I think you may be on to something. I ran the "Depends.ex e", as you
                        suggested, and it gave me the following warnings about my dll:
                        >
                        1.)Warning: At least one delay-load dependency module was not found.
                        >
                        2.)Warning: At least one module has an unresolved import due to a
                        missing export function in a delay-load dependent module.
                        >
                        Also it said there was an error opening file "DWMAPI.DLL ", the system
                        cannot find the file specified.
                        >
                        How do I add or fix this?
                        >
                        Thanks!
                        >
                        >
                        *** Sent via Developersdex http://www.developersdex.com ***
                        >

                        Comment

                        • Blaine

                          #13
                          RE: Error when calling vb dll subroutine from excel vba


                          Mike,

                          I'm using Windows XP, SP2


                          *** Sent via Developersdex http://www.developersdex.com ***

                          Comment

                          • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

                            #14
                            RE: Error when calling vb dll subroutine from excel vba

                            Searching for DWMAPI.Dll shows a lot of people running into this issue, but I
                            cannot say that I ever have. Here is a thread with a lot of information on
                            the subject:





                            "Blaine" wrote:
                            >
                            Mike,
                            >
                            I'm using Windows XP, SP2
                            >
                            >
                            *** Sent via Developersdex http://www.developersdex.com ***
                            >

                            Comment

                            • Blaine

                              #15
                              RE: Error when calling vb dll subroutine from excel vba


                              Mike,

                              Thanks for the reply. I found the "DWMAPI.DLL " file and placed it in my
                              system32 folder and reused "Depends.ex e" and the problem went away.
                              However, my excel vba still gives the missing assembly or dependencies
                              error. Any other ideas?

                              Thanks,
                              Blaine


                              *** Sent via Developersdex http://www.developersdex.com ***

                              Comment

                              Working...