The information in this article applies to:
SUMMARYWhen you are working with a Microsoft Excel PivotTable, you may want to determine its data source. To do this, use the SourceData property in Microsoft Visual Basic for Applications code. MORE INFORMATIONMicrosoft provides programming examples 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. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.aspA Microsoft Excel PivotTable can be based on a result set obtained via Microsoft Query from an external data source. When a PivotTable is created in this way, a Structured Query Language (SQL) SELECT statement is created. The SELECT statement describes which fields to use and from which table to select them. It also specifies any criteria that are applied to the result set. The SourceData property can be used to return the data source for a PivotTable object. If the data source is an external data source, then the return value for the SourceData property is an array that consists of an SQL connection string with the remaining elements as the query string broken into 200-character segments. For example, if you create a PivotTable that uses data from the NWind data source, and you want to see records from the Orders table with the following criteria
SELECT orders.EMPLOY_ID, orders.ORDER_AMTTo return the SQL connection string and SELECT statement for this sample PivotTable, you could create a macro similar to the following:
Note that if the first element, which is the Connection String, is greater
than 255 characters, it will be truncated. However, each additional element
makes up the SELECT statement and these elements are broken into strings of
200 characters each.
REFERENCESFor more information on the SourceData Property, click the Search button in Visual Basic Reference Help, and type: SourceData Additional query words: XL5 XL7 XL97 XL98 5.00a 5.00c 7.00a
Keywords : kbprg kbualink97 kbdta kbdtacode xlquery PgmHowto KbVBA |
Last Reviewed: November 9, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |