• In Excel, run an rundll32.exe + dll with variables ( Excel O’03 – WinXP SP3 – UK)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » In Excel, run an rundll32.exe + dll with variables ( Excel O’03 – WinXP SP3 – UK)

    Author
    Topic
    #456907

    Hi,

    Got some code in Excel that retrieves a variable from a database. Subsequently I update the database with a new value and then needs to trigger another update function contained in a DLL. The function requires 2 parameters (eg. ‘Ticker’ and ‘time period’). ‘Ticker’ are retrieved from the database and time period are always ‘DATE’.

    So from within Excel I need to send a line that in a command prompt looks like this:

    ‘rundll32.exe somedll.dll UpdateFunction Parameter1 Parameter2’

    Typing this directly in a command prompt works fine. From a lot of reading I’ve seen various suggestions, but haven’t been able to find one that does exactly what I
    need…

    My function so far is something like this…

    Function RunUpdate(ByRef Ticker As String) As Boolean
    Dim oShell
    Dim WScript As Object
    Dim Date$

    Date = Date

    Set WScript = CreateObject(“WScript.Shell”)
    oShell = WScript.Run(“cmd /K ‘rundll32.exe somedll.dll UpdateFunction Ticker Date”,1)
    Debug.Print oShell
    RunUpdate = True

    Set WScript = Nothing

    End Function

    However this function does not update…

    I expect that part of the problem is that the parameters are within the string sent to the command prompt.

    Does anyone know how this is ‘normally’ achieved?
    (I believe calling an outside dll with variable parameters must be something others do often…)

    THX

    Viewing 0 reply threads
    Author
    Replies
    • #1143601

      Try something like

      oShell = WScript.Run(“cmd /K ‘rundll32.exe somedll.dll UpdateFunction ” & Ticker & ” ” & Date,1)

      BTW I don’t think naming a variable Date is a good idea, since Date is also a built-in function.

      • #1143634

        Hi Hans,

        Thanks – I’ll give it a shot.

        ‘Date’ was actually sToday = Date (don’t think I would be allowed to use Date at all. If I remember correctly it is a reserved key word)

        Was typing this part directly in the msgbox – so it was more of a typo, sorry.

      • #1144167

        Another question on the same note…

        I read somewhere that the Wscript or the ‘runDLL32’ command in case it fails throws a 0 into some sort of a log file and that this error is trappable.

        Unfortunately I don’t remember where I saw it and I can’t find the article that I read this in…

        Would you by any chance have an idea of what I might be looking for here??

        THX

        • #1144169

          I have no idea; I hope that someone else can help you.

        • #1144317

          In the old days of DOS batch files, one could check a value called ERRORLEVEL. Does that sound like something that might be relevant to your application?

        • #1144343

          As a matter of interest, have you tried declaring the function in VBA as you would with a Windows API call to see if you can call it directly (it will depend on how the dll was built I think)?

          • #1144346

            Have just checked with the provider of the DLL – unfortunately this is not currently possible. Was a nice idea though grin

    Viewing 0 reply threads
    Reply To: Reply #1143634 in In Excel, run an rundll32.exe + dll with variables ( Excel O’03 – WinXP SP3 – UK)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel