作者:林林净洁_526 | 来源:互联网 | 2023-05-18 08:17
Okay,Ihaveanexcelmacrothatprocessesalotofdataandmakesalotofcharts.Iinheritedthe
Okay, I have an excel macro that processes a lot of data and makes a lot of charts. I inherited the code from a guy that recently retired, while the code functions it is very inefficient so I am rewriting it. One of the things I am trying to fix is he activated/selected everything. I prefer to use references and never select/activate anything.
好的,我有一个excel宏处理大量数据并生成大量图表。我继承了最近退休的人的代码,而代码功能效率非常低,所以我重写它。我试图解决的一件事是他激活/选择了一切。我更喜欢使用引用,从不选择/激活任何东西。
But I am running into a problem that when I create a new workbook or chart, it will steal focus from the original workbook. This is annoying, because I usually don't add the workbook object in my references for my main workbook.
但是我遇到了一个问题,当我创建一个新的工作簿或图表时,它会从原始工作簿中窃取焦点。这很烦人,因为我通常不会在我的主工作簿的引用中添加工作簿对象。
For example, when I use these lines, the new chart/workbook becomes active
例如,当我使用这些行时,新的图表/工作簿变为活动状态
Set wb = Workbooks.Add
Or Set wC = wb.Charts.Add
设置wb = Workbooks.Add或Set wC = wb.Charts.Add
I then use Workbooks(FileName).Activate
to reactivate the original workbook
然后我使用Workbooks(FileName).Activate重新激活原始工作簿
I find it annoying to have to do this every time, and was wondering if there was a way to prevent the new objects from becoming active.
我发现每次都必须这样做很烦人,并且想知道是否有办法阻止新对象变为活动状态。
Edit: I just realized that other actions cause the charts to steal focus, like moving the chart with this command wC.Move After:=wb.Worksheets(wb.Worksheets.Count)
编辑:我刚刚意识到其他动作导致图表窃取焦点,比如使用此命令移动图表wC.Move After:= wb.Worksheets(wb.Worksheets.Count)
1 个解决方案