ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ListObjects.Add error (https://www.excelbanter.com/excel-programming/366446-listobjects-add-error.html)

doug

ListObjects.Add error
 
I am trying to dynamically add a ListObject which references an external
SharePoint list to a worksheet in VSTO 2003.

I am able to do this in VBA using the following code:

Dim x(1) As Variant
x(0) = "http://192.168.0.33/GPDS/_vti_bin"
x(1) = "{1004279C-7047-448A-AD8B-B1A39ADCCFDE}"
ws.ListObjects.Add xlSrcExternal, x, True, xlYes, ws.Range("A1")

When I try to translate that to C# in VSTO 2003, I get an exception, "Bad
variable type," using the following code:
string [] myListSource = new string[3];
myListSource[0]="http://192.168.0.33/GPDS/_vti_bin";
myListSource[1]="{1004279C-7047-448A-AD8B-B1A39ADCCFDE}";
myListSource[2]="{3058AE3B-0603-4695-89E6-A949DF090D5D}";
Excel.Range rngTarget = ws.get_Range("A1",Type.Missing);
ws.ListObjects.Add(Excel.XlListObjectSourceType.xl SrcExternal,myListSource,true,Excel.XlYesNoGuess.x lYes,rngTarget);

The documentation for this method
(http://msdn2.microsoft.com/en-us/lib...cts.add.asp x)
states that I should be sending a string array of 3 elements...so I'm a
little confused as to why the VBA code works, unless its variant data type
behavior that allows it to work. Element 0 is the URL of the SharePoint
site, element 1 is the GUID of the list, element 2 is the GUID of the view.

Can anyone tell me where I've gone wrong?

--
-Doug


All times are GMT +1. The time now is 10:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com