在Excel VBA中设置活动工作簿的值 [英] Setting value of active workbook in Excel VBA

查看:846
本文介绍了在Excel VBA中设置活动工作簿的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在已经设置了我的工作簿,在这个工作簿被硬编码到Set命令的地方,我想知道是否有这样做的方法,所以我可以把它放在哪里?所以无论这个代码在哪里(在另一个工作簿中),代码将适应它的新环境。



这是否有意义?



以下是我现在正在使用的,我想要做的是针对 ActiveWorkbook 或可以使用一些类似的东西。因为这将被设置在代码的开头,而不是中间。



设置wbOOR = Application.Workbooks(打开订单Report.xlsm )

解决方案

你可能在之后设置wbOOR = ThisWorkbook



只是为了澄清



ThisWorkbook 将始终引用代码所在的工作簿



ActiveWorkbook 将引用活动的工作簿



在处理多个工作簿时,请注意如何使用它。这真的取决于你想要实现哪一个是最好的选择。


I for now have my workbook set up this way, in where the workbook is hard coded into the Set command, I am wondering if there is a way of doing this so I can have it where it is fluid? So no matter where this code is place (in another workbook) the code will adapt to it's new surroundings.

Does this make sense?

Below is what I am using now, what I'd like to have it do is for the ActiveWorkbook or something of the sort be used instead. Since this will be set at the beginning of the code and not the middle.

Set wbOOR = Application.Workbooks("Open Order Report.xlsm")

解决方案

You're probably after Set wbOOR = ThisWorkbook

Just to clarify

ThisWorkbook will always refer to the workbook the code resides in

ActiveWorkbook will refer to the workbook that is active

Be careful how you use this when dealing with multiple workbooks. It really depends on what you want to achieve as to which is the best option.

这篇关于在Excel VBA中设置活动工作簿的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆