Check if ListObject exists ? VBA to ExcelDNA code conversion

1,492 views
Skip to first unread message

jonesn1

unread,
May 19, 2015, 5:54:56 PM5/19/15
to exce...@googlegroups.com
How do you create this function in ExcelDNA?
Function TableExists(ws As Worksheet, tblNam As String) As Boolean
 
Dim oTbl As ListObject
 
For Each oTbl In ws.ListObjects
   
If oTbl.Name = tblNam Then
     
TableExists = True
     
Exit Function
   
End If
 
Next oTbl
 
TableExists = False
End Function

Govert van Drimmelen

unread,
May 19, 2015, 6:21:46 PM5/19/15
to exce...@googlegroups.com, nathan.lin...@gmail.com
In what context do you want to use this function?

It's fine as it is if you just want to call it from other macros in your add-in (you just need a reference to the Microsoft.Office.Interop.Excel interop assembly, and and Imports at the top of your Module).

-Govert

jonesn1

unread,
May 19, 2015, 7:24:37 PM5/19/15
to exce...@googlegroups.com, nathan.lin...@gmail.com
Wow...I feel foolish...forgot to mention the language I wanted to translate that VBA code into. :)  

I had a project written in F# containing other functions I use and was having a hard time with the translation of this VBA to F#...but obviously the easier thing to do is just to add a VB project to my F# solution in Visual Studio, copy the code in as is with appropriate Imports, and then reference the vb dll so that a copy is created in the F# project path and include an ExternalLibrary reference to the vb dll in the dna file.  I was able to do this and have it working as expected.  

Thank you for the quick response.  I echo what so many have already said...your work is amazing!  I only wish I had found ExcelDNA much earlier.
Reply all
Reply to author
Forward
0 new messages