views:

1283

answers:

1

I have an Excel workbook with a number of features:

  • One main user-facing sheet
  • One summary sheet based on the user-facing sheet's data
  • A number of graphs based on the user-facing sheet's data (as in, the type of graphs with a separate tab for them, rather than objects within a worksheet - I'm not sure if they have a special name or special properties)
  • A series of 'background' worksheets that calculate the values for the user-facing sheet
  • A macro to allow the user to sort the user-sheet by any column they wish, which is referenced in the user-facing sheet's Worksheet_SelectionChange event

However, for distribution I'd like to cull the sheets for simplicity (and file size - the entire data query is included on one of the sheets). I still need to calculate the values for the user-facing sheet, but it's only done once per dataset, so that can quite happily be copied as formatting then values.

The trouble, however, is transferring the dependent sheet, graphs and macros across to a new workbook so that instead of referencing the old workbook, they reference the new versions of the sheet. Ideally I'd like to do this with VBA or something, but my Google searches thus far don't seem to have turned up much of relevance.

Does anyone know how to do this?

+1  A: 

I'm not sure I entirely understand your question, but what I think that you want to do is to create a new version of your workbook, with less worksheets in it??

To do that in VBA, this code snippet is a good place to start:

Sub Macro1()
    ActiveWorkbook.SaveAs Filename:= _
        [your path here]\Book2.xls", FileFormat:=xlNormal, _

    Sheets("Sheet2").Select
    ActiveWindow.SelectedSheets.Delete
End Sub

Creating a copy of the entire workbook, and then deleting what you don't need will make sure that the links do not reference the old workbook.

Once you have created the new workbook, with links intact, it is then pretty easy to remove all the things (calculations, etc.) that you don't need.

Stewbob