Article ID: 151278
Article Last Modified on 10/11/2006
DDERequest(<channel>, "QueryDefinition/n")
DDERequest(<channel>, "ODBCSQLStatement/n")where <channel> is the dynamic data exchange (DDE) to Microsoft Query channel variable.
DDERequest(<channel>, "QueryDefinition/n")
DDERequest(<channel>, "ODBCSQLStatement/n")where <channel> is the DDE to Microsoft Query channel variable,
Sub TestArrayQueryDefinition()
' Activate a worksheet.
Worksheets(1).Activate
' Initiate a Channel to MSQuery.
Chan = DDEInitiate("MSQUERY", "System")
' Give the user control in Microsoft Query so they can select data
' from a database and return to Excel.
DDEExecute Chan, "[UserControl('&Return to Excel',3,true)]"
' At this point the code opens Microsoft Query and waits
' for the user to select a Data Source, Data Table(s), and data to
' return to Microsoft Excel.
' To request the Query Definition be parsed into of 50 character
' sections...
QryDefArray = DDERequest(Chan, "QueryDefinition/50")
' To format the parsed Query Definition data...
ArrayLen = UBound(QryDefArray, 1)
Range("A1").Value = "Query Definition (renamed Column Names) in " _
& ArrayLen & " parts:"
' If the Array length is one then a one dimension array is returned,
' if the Array length is greater than one, a two dimension array is
' returned.
If ArrayLen = 1 Then
' Place the single line of data on the worksheet and remove wrap text.
Range("A2") = QryDefArray(1): Range("A2").WrapText = False
Else
' Place the parsed lines of data on the worksheet and remove wrap
' text.
For i = 1 To ArrayLen
Range("A" & i) = QryDefArray(i, 1)
Range("A" & i).WrapText = False 'To undo wrap text
Next i
End If
End Sub
Additional query words: XL5 XL7 XL97 5.00c 8.00 97 XL
Keywords: kbprogramming KB151278