VBA Issues with WorksheetFunction.RTD("tos.rtd", "", Param, Sym)

mdm2020

New Member
Joined
Nov 9, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
In my Function/Sub I created the following two bits of simple code
VBA Code:
Sub MyTstToS3()
    Dim Bid As Long
    Dim Symbol, Descr As String
    
    Symbol = ".NVDA211217C320"
    Descr = MyToS3("DESCRIPTION", Symbol)
    Bid = MyToS3("BID", Symbol)

    Range("A1") = Descr
    Range("A2") = Bid
End Sub

Function MyToS3(Param As String, Sym As String) As Variant
        MyToS3 = Excel.WorksheetFunction.RTD("tos.rtd", "", Param, Sym)
End Function

If I Just run this I get an immediate Run-time Error: Type Mismatch and highlights Descr = MyToS3("DESCRIPTION", Symbol)
Now if I enter the following in any cell within the spreadsheet
=RTD("tos.rtd", "", "DESCRIPTION", ".NVDA211217C320")
Viola, the next Mismatch error happens at the next statement. Only when I add somewhere in the spreedsheet the below
=RTD("tos.rtd", "", "BID", ".NVDA211217C320")
does the code run through without a problem. The Symbol has to be the same because as soon as I change it it comes up with
the mismatch error again.

I am at loss why the Excel.WorksheetFunction.RTD will not works without the exact same RTD call with the exact same parameters needing
to be called somewhere in the spreadsheet. It is as if the fact that it is called in the spreadsheet and thereby running in the background that
the connection is open and only then the function in the VBA code works. Very frustrating.

I even tried to pre-populate the contents in a spreadsheet via a macro before calling the function but this cannot be done in one call as the
cells with the RTD statements will not update until it exits the macro.

Any ideas, help would be greatly appreciated.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top