[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

VSTO Excel 2007 Addin, Questions about MSQuery Connection

Posted on 2010-11-16
3
Medium Priority
?
928 Views
Last Modified: 2013-11-10
I am trying to create an Excel 2007 Addin that works pretty much like a MSQuery Connection. I have code working where I can get data from a saved MSQuery conenction but when done manually it creates the data in a table. When done with just QueryTable.Add I get the data but no surrounding Table or ListObject. I have tried creating a ListObject but then don't know how to connect the ListObject to the MSQuery Connection. I'll take either direction.
oQueryTable = moToolsExcelActiveSheet.QueryTables.Add("FINDER;" & sDQYTempFileName, oTarget, sSQL)
oQueryTable.Name = "QT Name"
oQueryTable.MaintainConnection = False
oQueryTable.FieldNames = True
oQueryTable.RowNumbers = False
oQueryTable.FillAdjacentFormulas = False
oQueryTable.PreserveFormatting = True
oQueryTable.RefreshOnFileOpen = False
oQueryTable.BackgroundQuery = False
oQueryTable.RefreshStyle = Interop.Excel.XlCellInsertionMode.xlInsertDeleteCells
oQueryTable.SavePassword = True
oQueryTable.SaveData = True
oQueryTable.AdjustColumnWidth = True
oQueryTable.RefreshPeriod = 0
oQueryTable.PreserveColumnInfo = True
oQueryTable.CommandType = Interop.Excel.XlCmdType.xlCmdSql
oQueryTable.CommandText = sSQL 
oQueryTable.Refresh(BackgroundQuery:=False)
oQueryTable.WorkbookConnection.Name = "Test Connection"

Open in new window

0
Comment
Question by:cpv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 total points
ID: 34258435
I think you can just use Listobjects.Add and specify the SourceType as 0, the Source as your connection string, and the Destination. That should automatically create an associated querytable that you can then manipulate. In VBA terms:

With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=connection_string, Destination:=Range("$A$1")).QueryTable
        .CommandType = xlCmdTable
        .CommandText = SQL_here
        .RowNumbers = False
' etc

Open in new window

0
 
LVL 24

Expert Comment

by:Tracy
ID: 34459689
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question