Microsoft KB Archive/327572

= PRB: You Cannot Change the Data Source for a PivotTable in Excel for an Analysis Services Connection =

Article ID: 327572

Article Last Modified on 2/20/2007

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition
 * Microsoft SQL Server 2000 Standard Edition
 * Microsoft SQL Server 2000 Analysis Services

-



This article was previously published under Q327572



SYMPTOMS
After you change the server name of the computer that is running Analysis Services that an Excel PivotTable is using, you cannot manually change the connection information to the new folder or server.



WORKAROUND
NOTE: Microsoft has tested the following code sample on Excel 2000.

To work around this problem, use Visual Basic for Applications to programmatically change the data source for a PivotTable in Excel for an Analysis Services connection:  Start Excel 2000. Open the file that contains the PivotTable (or PivotTables) that you want to modify. On the Tools menu, point to Macro, and then click Visual Basic Editor. On the Insert menu, click Module.  In the module, insert the following macro code: Option Explicit

Sub ChangeServer

Dim sh As Worksheet, qy As QueryTable Dim pt As PivotTable, pc As PivotCache Dim OldPath As String, NewPath As String Dim strOld As String, strNew As String

' Replace the following paths with the original path or    ' server name where your database resided, and the new ' path or server name where your database now resides. OldPath = &quot; &quot; NewPath = &quot; &quot;

For Each sh In ActiveWorkbook.Sheets

For Each pt In sh.PivotTables

strOld = pt.PivotCache.Connection strNew = Replace(strOld, OldPath, NewPath) pt.PivotCache.Connection = strNew pt.PivotCache.Refresh

Next pt

Next sh

End Sub  Change OldPath and NewPath to the appropriate server name. If you use a server that does not exist for NewPath, the multidimensional connection wizard opens when you perform step 12 of this procedure. On the File menu, click Close, and then return to Microsoft Excel.</li> Switch to the first sheet.</li> On the Tools menu, point to Macro, and then click Macros.</li> In the list of macros, select the ChangeServer macro, and then click Run.</li> A dialog box opens in which you can change the server and that lists the available cubes. Changing the cube does not change the cube for your queries that are using this code.</li> The dialog box opens for each of the PivotTables in turn.</li> Update your PivotTable server name.</li> Save the spreadsheet. You may want to remove the macro before you distribute the spreadsheet.</li></ol>

Keywords: kbprb KB327572

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.