Article ID: 125492
Article Last Modified on 10/11/2006
Activate*
AllowEdit
BuildSQL*
Close
Command*
Exit*
Fetch and Fetch.Advise
Fetch.Unadvise
Logoff*
Logon*
ODBCLogon*
Open*
QueryNow
SaveAs
SetWindowState
UserControl*
ViewPane
Sub UsingSystemChan()
Dim chan As Integer
Dim sql As String
' Establish DDE conversation using system channel
chan = DDEInitiate("MSQUERY", "System")
' logon using NWind data source
DDEExecute chan, "[Logon('NWind')]"
' Execute an SQL query to retrieve all records from Customer table
DDEExecute chan, "[Open('SELECT Custmr_ID FROM Customer')]"
'Return data to Sheet1 at cells A1:A63
DDEExecute chan, "[Fetch('Excel', 'Sheet1', 'R1C1:R63C1', 'All')]"
' Close the DDE channel
DDETerminate chan
End Sub
Sub UseQueryChannel()
Dim chan As Integer
Dim NRows, NCols
' Establish DDE conversation using query channel
' ** Note that QUERY1 must be open in Microsoft Query
' in order for the following command to work
chan = DDEInitiate("MSQUERY", "query1")
'Determine the number of rows and columns in query1
NRows = DDERequest(chan, "NumRows")
NCols = DDERequest(chan, "NumCols")
' Return the data in Query1 to Sheet1 starting at A1.
' ** The following two lines should be entered on one line.
DDEExecute chan,"[Fetch('Excel', 'Sheet1', 'R1C1:R" & NRows(1) & "C"
& NCols(1) & "', 'All')]"
' Close the DDE channel
DDETerminate chan
End Sub
Microsoft provides examples of Visual Basic for Applications procedures for
illustration only, without warranty either expressed or implied, including,
but not limited to the implied warranties of merchantability and/or fitness
for a particular purpose. The Visual Basic procedures in this article are
provided 'as is' and Microsoft does not guarantee that they can be used in
all situations. While Microsoft Support professionals can help explain the
functionality of a particular macro, they will not modify these examples to
provide added functionality, nor will they help you construct macros to
meet your specific needs. If you have limited programming experience, you
may want to consult one of the Microsoft Solution Providers. Solution
Providers offer a wide range of fee-based services, including creating
custom macros. For more information about Microsoft Solution Providers,
call Microsoft Customer Information Service at (800) 426-9400.
DDE commands
Additional query words: 5.00 5.00a 5.00c 7.00 7.00a
Keywords: kbinterop KB125492