Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 759499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:36:15+00:00 2026-05-14T15:36:15+00:00

I often use Excel with pivot tables based on .cub files for OLAP-type analysis.

  • 0

I often use Excel with pivot tables based on .cub files for OLAP-type analysis. This is great except when you want to move the xls and you realise internally it’s got a non-relative reference to the location of the .cub file. How can we cope with this – ie make it convenient to move around xls files that depend on .cub files?

The best answer I could come up with is writing a macro that updates the pivot tables’ reference to the .cub file location….so I’ll pop that in an answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:36:15+00:00Added an answer on May 14, 2026 at 3:36 pm

    Here’s the macro I ended up with. Clearly this makes some assumptions that might not be right for you, e.g. it updates all pivot tables in the workbook to use the same .cub file.

    It loops through the workbook’s Pivot Table connections to use a .cub file with
    the same name as this .xls file, in the same directory. This assumes that the PivotCaches are not using LocalConnections – check that ActiveWorkbook.PivotCaches(1).UseLocalConnection = False.

    Sub UpdatePivotTableConnections()
        Dim sNewCubeFile As String
        sNewCubeFile = ActiveWorkbook.Path & Replace(ActiveWorkbook.Name, ".xls", ".cub", , , vbTextCompare)
    
        Dim iPivotCount As Integer
        Dim i As Integer
        iPivotCount = ActiveWorkbook.PivotCaches.Count
    
        ' Loop through all the pivot caches in this workbook. Use some 
        ' nasty string manipulation to update the connection.
        For i = 1 To iPivotCount
        With ActiveWorkbook.PivotCaches(i)
            ' Determine which cub file the PivotCache is currently using
            Dim sCurrentCubeFile As String
            Dim iDataSourceStartPos As Integer
            Dim iDataSourceEndPos As Integer
            iDataSourceStartPos = InStr(1, .Connection, ";Data Source=", vbTextCompare)
            If iDataSourceStartPos > 0 Then
                iDataSourceStartPos = iDataSourceStartPos + Len(";Data Source=")
                iDataSourceEndPos = InStr(iDataSourceStartPos, .Connection, ";", vbTextCompare)
                sCurrentCubeFile = Mid(.Connection, iDataSourceStartPos, iDataSourceEndPos - iDataSourceStartPos)
    
                ' If the PivotCache is using a different cub file then update the connection to use the new one.
                If sCurrentCubeFile <> sNewCubeFile Then
                    .Connection = Left(.Connection, iDataSourceStartPos - 1) & sNewCubeFile & Right(.Connection, Len(.Connection) - iDataSourceEndPos + 1)
                End If
            End If
        End With
        Next i
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 389k
  • Answers 389k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer One idea: maintain a std::deque which gets an iterator into… May 15, 2026 at 12:41 am
  • Editorial Team
    Editorial Team added an answer Scope simply means some selected range. So if you use:… May 15, 2026 at 12:41 am
  • Editorial Team
    Editorial Team added an answer You can do like this: byte[] data = Key .Split(new… May 15, 2026 at 12:41 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.