Run Function from other File in Module

  • Hi,


    I got in a XLS-File a Function (CheckData), which should be started from another Modul of XLS-File2.


    Public Function CheckData(Value As String)
    ...


    in the same modul it works like:
    ---
    res = CheckData(Value)


    How can I do that in the other modul / file?
    something like:
    res = File1.CheckData(Value)


    At the moment I load the other sheet, but it gives me an error before (compiling error), because the function is unknown (of course, it hasn't loaded yet...) :(



    THX
    I can't copy the function to File2, because the function should be used in many other files as well. Therefore I can't just copy it.";

  • Re: Run Function from other File in Module



    THX


    I tried that way, but it always say "Object necessary" Runtime-Error 424
    I did also a new Function: test()
    when I start it in File2 no Prob! But in File1 it is not working!


    What do I do wrong?


    Are ther any examples in the net, that I can check the syntax?


    Is there something like "import" necessary?



    THX

  • Re: Run Function from other File in Module


    Hi,


    In the workbook containing the function, give the VBAProject a unique name (eg "ABC") and save the workbook.


    In the second workbook go to the VBE and select References from the Tools menu and set a reference to the ABC project. You should now be able to use your function.


    HTH

  • Re: Run Function from other File in Module



    I tried the last 20 minutes to do that...
    Sorry, but how can I do that?
    Menu (VBE Editor) -> Tools -> References -> ?


    Could it be, that in V97 (which I use) that this is not possible?

  • Re: Run Function from other File in Module


    It does work in Excel97 - that's what I am using at the moment ;)


    What part are you struggling with? Changing the name of the VBAProject in the workbook that contains the function, or setting the reference in the other workbook?

  • Re: Run Function from other File in Module


    Quote from Richie(UK)

    It does work in Excel97 - that's what I am using at the moment ;)


    What part are you struggling with? Changing the name of the VBAProject in the workbook that contains the function, or setting the reference in the other workbook?


    The Modul itself has already a different name.
    Has it be the same as the function-name?


    I think it is setting the reference. The Prob is, that I don't have here a english Version of Excel. I thought I'm in the right menu-point.
    But there I can find only links to DLLs...
    Do you know any links in the Internet, where I can find some pictures? So I can corespond to the right point (hopefully...)


    :?

  • Re: Run Function from other File in Module


    now it worked. Don't know why it wasn't doint its job from the beginning!


    THX :thanx:

  • Re: Run Function from other File in Module


    Hi again,


    further Problem.
    :yikes:


    When I close the main sheet, the other sheet (which is referenced) is still open. It should be closed all together -> all in one!


    I tried with Auto_close, but it is not working. Are there any solutions (that both sheets are closed)?


    Sub Auto_close()
    PVName = "PersonalABC.xls"
    Workbooks(PVName).Close
    End Sub


    It says, that there is still a connection (reference) opened...



    Thx

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!