首页 \ 问答 \ 如何从工作簿B中调用Workbook_Open on Workbook A?(How can I call Workbook_Open on Workbook A from Workbook B?)

如何从工作簿B中调用Workbook_Open on Workbook A?(How can I call Workbook_Open on Workbook A from Workbook B?)

我的情况是我试图从工作簿B打开工作簿A并运行Workbook_Open子例程。 仅仅使用Workbooks.Open("c:\myworkbook.xls")是我需要在Workbook_Open子例程运行之前在Workbook A中Workbooks.Open("c:\myworkbook.xls")数据。

我有两个想法,我都不喜欢,所以我想知道是否有更好的方法。 我的两个想法如下。

选项1:打开工作簿A,禁用宏,植入数据,保存并关闭工作簿,然后在启用宏的情况下重新打开它。 我不想这样做的原因是:我正在处理一个具有相当数量格式的.xls文件(基本上我模拟人类将如何使用它数千次)并保存文件数千次可能导致文件损坏。 此外,这需要相当长的时间才能打开工作簿两次,而且对我来说似乎没有任何效率。 其中一个重点是速度和效率,以及最快的周转时间。

选项2:将Workbook_Open代码复制为模块中其他位置的公共子例程。 这是两者中更为理想的问题,但问题是我不一定有权执行此操作,这样做会涉及大量繁文缛节,红旗等。

有没有办法做这样的事情:

Workbooks("Workbook A").Application.Run (Workbooks("Workbook A").Workbook_Open)

My situation is that I am trying to open Workbook A from Workbook B and run the Workbook_Open subroutine. The issue with just simply using Workbooks.Open("c:\myworkbook.xls") is that I need to plant data in Workbook A before the Workbook_Open subroutine runs.

I have two ideas, neither of which I particularly like, so I was wondering if there was a better way. My two ideas are as follows.

Option 1: Open Workbook A with macros disabled, plant the data, save and close the workbook then re-open it with macros enabled. The reasons I would prefer not to do this is: I am dealing with a .xls file that has a fair amount of formatting (basically I am simulating how a human would use it thousands of times over) and saving the file thousands of times may cause the file to corrupt. Additionally this takes a fair amount of time to open the workbook twice, and it does not seem at all efficient to me. One of the big points of emphasis is speed and efficiency with the quickest turnaround time.

Option 2: Duplicate the Workbook_Open code as a public subroutine in elsewhere within a module. This is the more desirable of the two, but the issue is I do not necessarily have permission to perform this action and doing this will involve plenty of red tape, red flags, etc.

Is there any way to do something like this:

Workbooks("Workbook A").Application.Run (Workbooks("Workbook A").Workbook_Open)

原文:https://stackoverflow.com/questions/27869616
更新时间:2022-04-08 21:04

最满意答案

DataFrame视为Series的集合会很有用,其中每个Series都是DataFrame一列。

当您沿axis=1取平均值时,您将获得一个Series其中包含Panel 10个项目中每个项目的30个元素。 如果您收集这10个Series您将获得一个包含30行和10列的DataFrame

类似地,当你沿着axis=2取平均值时,你会得到一个长度为20的Series ,用于面板中的每个项目。 将这10个Series收集在一起,可以得到一个包含20行和10列的DataFrame

当您计算沿axis=0的平均值axis=0 ,您将获得平均项目,该项目预期与面板中的每个项目具有相同的形状,即20乘30。

下面的一些代码可能有助于阐明我的观点:

In [1]: panel = pd.Panel(np.random.rand(10,20,30))

# Note that for a single item in the panel, the mean along 
# either of its axes is a `Series`:

In [2]: type(panel[0].mean(axis=0))
Out[2]: pandas.core.series.Series

In [3]: type(panel[0].mean(axis=0))
Out[3]: pandas.core.series.Series

In [3]: panel[0].mean(axis=0)
Out[3]:
0     0.569390
1     0.497762
2     0.616333
3     0.608153
4     0.524008
5     0.478621
6     0.492827
7     0.461240
8     0.573557
9     0.654757
10    0.541066
11    0.572929
12    0.482214
13    0.576898
14    0.362965
15    0.493355
16    0.491790
17    0.567756
18    0.426404
19    0.514235
20    0.416983
21    0.455843
22    0.603592
23    0.387520
24    0.470060
25    0.506414
26    0.545156
27    0.525211
28    0.526378
29    0.486419
dtype: float64

It can be useful to think of a DataFrame as a collection of Series, where each Series is a column in the DataFrame.

When you take the mean along axis=1, you obtain a Series with 30 elements for each of the 10 items in the Panel. If you collect these 10 Series you obtain a DataFrame with 30 rows and 10 columns.

Similarly , when you take the mean along axis=2, you end up with a Series of length 20 for each of the 10 items in the panel. Collecting these 10 Series together gives you a DataFrame with 20 rows and 10 columns.

When you calculate the mean along axis=0, you obtain the average item, which is expected to have the same shape as each item in the panel, i.e. 20 by 30.

Below some code that may help elucidate my point:

In [1]: panel = pd.Panel(np.random.rand(10,20,30))

# Note that for a single item in the panel, the mean along 
# either of its axes is a `Series`:

In [2]: type(panel[0].mean(axis=0))
Out[2]: pandas.core.series.Series

In [3]: type(panel[0].mean(axis=0))
Out[3]: pandas.core.series.Series

In [3]: panel[0].mean(axis=0)
Out[3]:
0     0.569390
1     0.497762
2     0.616333
3     0.608153
4     0.524008
5     0.478621
6     0.492827
7     0.461240
8     0.573557
9     0.654757
10    0.541066
11    0.572929
12    0.482214
13    0.576898
14    0.362965
15    0.493355
16    0.491790
17    0.567756
18    0.426404
19    0.514235
20    0.416983
21    0.455843
22    0.603592
23    0.387520
24    0.470060
25    0.506414
26    0.545156
27    0.525211
28    0.526378
29    0.486419
dtype: float64

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)