ExcelQuestioner
New Member
- Joined
- Jan 14, 2015
- Messages
- 6
Hi,
Thanks in advance for any advice.
I've been attempting to convert my Excel VBA projects to VB.NET, but have been unable to translate the VBA code below into VB.NET
The objective is to create a ListObject Excel Table using ODBC to connect to SQL Server.
Thanks again
---
Sub CreateListObjectFromODBCConnectionToSQL()
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC;DSN=SQL;UID=DbViewer;PWD=*;APP=Microsoft Office 2013;WSID=*", Destination:=Range("$A$1")).QueryTable
.CommandText = Array("SELECT * FROM Table1")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_Query_from_SQL"
.Refresh BackgroundQuery:=False
End With
End Sub
Thanks in advance for any advice.
I've been attempting to convert my Excel VBA projects to VB.NET, but have been unable to translate the VBA code below into VB.NET
The objective is to create a ListObject Excel Table using ODBC to connect to SQL Server.
Thanks again
---
Sub CreateListObjectFromODBCConnectionToSQL()
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC;DSN=SQL;UID=DbViewer;PWD=*;APP=Microsoft Office 2013;WSID=*", Destination:=Range("$A$1")).QueryTable
.CommandText = Array("SELECT * FROM Table1")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_Query_from_SQL"
.Refresh BackgroundQuery:=False
End With
End Sub