|
把下面的代码复制粘贴到 THISWORKBOOK 里
文件另存为 XLSM- Private Sub Workbook_Open()
- Dim strCon As String, iPath As String, i As Integer, iFlag As String, iStr As String
- strCon = ActiveSheet.PivotTables(1).PivotCache.Connection
- Select Case Left(strCon, 5)
- Case "ODBC;"
- iFlag = "DBQ="
- Case "OLEDB"
- iFlag = "Source="
- Case Else
- Exit Sub
- End Select
- iStr = Split(Split(strCon, iFlag)(1), ";")(0)
- iPath = Left(iStr, InStrRev(iStr, "") - 1)
- With ActiveSheet.PivotTables(1).PivotCache
- .Connection = VBA.Replace(strCon, iPath, ThisWorkbook.Path)
- .CommandText = VBA.Replace(.CommandText, iPath, ThisWorkbook.Path)
- End With
- End Sub
复制代码 |
|