将 Excel 工作表、宏和图表从一个工作簿复制到另一个工作簿,并将链接移动到新工作簿

发布于 2024-07-27 23:58:59 字数 545 浏览 2 评论 0原文

我有一个具有许多功能的 Excel 工作簿:

  • 一个面向用户的主要工作表
  • 一个基于面向用户的工作表数据的摘要工作
  • 表 一些基于面向用户的工作表数据的图表(例如,带有它们的单独选项卡,而不是工作表中的对象 - 我不确定它们是否有特殊名称或特殊属性)
  • 一系列“背景”工作表,用于计算面向用户的工作表的值
  • 允许用户使用的宏按他们希望的任何列对用户工作表进行排序,该列在面向用户的工作表的 Worksheet_SelectionChange 事件中引用

但是,为了分发,我想剔除工作表以简化工作表(以及文件大小 - 整个数据查询都包含在一个工作表中)的床单)。 我仍然需要计算面向用户的工作表的值,但每个数据集只执行一次,因此可以很高兴地将其复制为格式化值。

然而,问题在于将依赖的工作表、图形和宏传输到新工作簿,这样它们就不会引用旧工作簿,而是引用工作表的新版本。 理想情况下,我想使用 VBA 或其他东西来完成此操作,但到目前为止我的 Google 搜索似乎没有发现太多相关性。

有谁知道如何做到这一点?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饮湿 2024-08-03 23:58:59

我不确定我完全理解你的问题,但我认为你想要做的是创建一个新版本的工作簿,其中的工作表更少?

要在 VBA 中执行此操作,此代码片段是一个很好的起点:

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

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

创建整个工作簿的副本,然后删除不需要的内容,以确保链接不会引用旧工作簿。

创建新工作簿且链接完好无损后,就可以很容易地删除所有不需要的内容(计算等)。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文