B
Bear S.
It's important to note that oQueryTable implements Excel.QueryTable
Imports Excel = Microsoft.Office.Interop.Excel
Public Class GetData
Dim ExcelApp As Excel.Application
Dim XlCmdType As Excel.XlCmdType
Dim XlCellInsertionMode As Excel.XlCellInsertionMode
Dim XL As New Use_Excel
Dim count As Short = 0
Public Sub Get_Data(ByVal family As String, ByVal Table As String)
count += 1
'
'To be used to get data from the data base
'
Dim Workbook As Excel.Workbook
Workbook = XL.NewWorkbook(Excel.XlWBATemplate.xlWBATWorksheet)
Dim Worksheet As Excel.Worksheet
Worksheet = XL.NewWorksheet()
Worksheet = CType(Workbook.Worksheets(count), Excel.Worksheet)
Dim DBPath As String = Environment.CurrentDirectory & "\"
Dim query_cmd As New oQueryTable
Dim destination As Excel.Range
destination = CType(Worksheet, Excel.Worksheet).Range("A1")
Dim str_DataBase As String = DBPath & family & ".mdb\"
Dim connection As Object = "<some relevant string>"
query_cmd.CommandType = XlCmdType.xlCmdTable
query_cmd = Worksheet.QueryTables.Add(connection, destination)
End Sub
End Class
My problem is specifically with the line:
query_cmd = Worksheet.QueryTables.Add(connection, destination)
it looks like i followed Cindy M.'s suggestions such that:
QueryTable=...QueryTables.Add(connection,destination) with the exception
that QueryTables only shows up by intellisense when Worksheet is used but not
when Excel.Activeworkbook is... I don't have any errors (according to
intellisense) but it throws an invalid cast exception: Unable to cast COM
object of type 'System._ComObject' to class type '_Program.oQueryTable'.
Thanks in advance for your help.
Imports Excel = Microsoft.Office.Interop.Excel
Public Class GetData
Dim ExcelApp As Excel.Application
Dim XlCmdType As Excel.XlCmdType
Dim XlCellInsertionMode As Excel.XlCellInsertionMode
Dim XL As New Use_Excel
Dim count As Short = 0
Public Sub Get_Data(ByVal family As String, ByVal Table As String)
count += 1
'
'To be used to get data from the data base
'
Dim Workbook As Excel.Workbook
Workbook = XL.NewWorkbook(Excel.XlWBATemplate.xlWBATWorksheet)
Dim Worksheet As Excel.Worksheet
Worksheet = XL.NewWorksheet()
Worksheet = CType(Workbook.Worksheets(count), Excel.Worksheet)
Dim DBPath As String = Environment.CurrentDirectory & "\"
Dim query_cmd As New oQueryTable
Dim destination As Excel.Range
destination = CType(Worksheet, Excel.Worksheet).Range("A1")
Dim str_DataBase As String = DBPath & family & ".mdb\"
Dim connection As Object = "<some relevant string>"
query_cmd.CommandType = XlCmdType.xlCmdTable
query_cmd = Worksheet.QueryTables.Add(connection, destination)
End Sub
End Class
My problem is specifically with the line:
query_cmd = Worksheet.QueryTables.Add(connection, destination)
it looks like i followed Cindy M.'s suggestions such that:
QueryTable=...QueryTables.Add(connection,destination) with the exception
that QueryTables only shows up by intellisense when Worksheet is used but not
when Excel.Activeworkbook is... I don't have any errors (according to
intellisense) but it throws an invalid cast exception: Unable to cast COM
object of type 'System._ComObject' to class type '_Program.oQueryTable'.
Thanks in advance for your help.