Answered: How do you declare an object reference variable for an OLE object?

Hi, I’m trying to write a function that will write excel data to a particular worksheet on an existing excel spreadsheet. I understand how to write this data to the spreadsheet and have that working, but I want to write a function in a script library and call that function from my agent… Here’s a code snippet…

Use “Reports”

Dim report As Reports

Set xlApp = CreateObject(“Excel.application”)

xlApp.Visible = True

Set xlBook = xlApp.Workbooks.Open (filename ) Set xlWs = xlBook.Worksheets(2)

Call report.writeExcelData(xlWs)

I get a compile error on the last line of the code. It says that there is a type mismatch on xlWs. I have defined the xlWs as a variant inside the function, but it doesn’t like that. In every example I’ve seen, I’ve never seen anyone actually dim a reference that will eventually be a object reference variable to an OLE object. Is there a way to do this? If so, how?

tia,

Heather Smith

Subject: How do you declare an object reference variable for an OLE object?

You are using scripts from “Reports”. Use “Reports”

So you have to check what the function writeExcelData accepts. Currently you are passing a workwheet into the function (Call report.writeExcelData(xlWs)). The function may accept some other object type.

Subject: RE: How do you declare an object reference variable for an OLE object?

I wrote the function inside of reports, but I do not know what to call the variable type because I have never seen someone declare a variable for an object reference.

Does someone know how to do this?

Thank you!

Heather Smith

Subject: Variant should work.

Dim xlWs As VariantSet xlWs = …

Sub writeExcelData(xlWs As Variant)

Subject: Variant does work!

Bill,You are right! When I went back into the agent and commented those lines of code back in that would not compile it indeed worked… I’ve found that sometimes the lotus script compiler doesn’t refresh completely.

This function writes data to a previously declared excel worksheet.

Function writeExcelData(vc As NotesViewEntryCollection, xlWs As Variant, startingPoint As String )

For x = 1 To vc.Count

Set entry = vc.GetNthEntry(x)

cp=0 ’ reset the column position

Forall columns In entry.ColumnValues

xlWs.Range(startingPoint).OffSet(x,cp).value=columns

cp= cp + 1

End Forall

Next

End Function

Thank you!

Heather Smith