本文介绍了VBA事件:在使用workbook_open运行代码之前加载工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在工作簿打开完毕后运行一个VBA宏。我试图使用workbook_open,但是在工作簿打开完成之前运行。这对我来说不起作用,因为我需要像这样循环遍历每张表单。

  Private Sub Workbook_Open()

Dim ws As Worksheet

对于每个ws在ActiveWorkbook.Worksheets
'做每个工作表上的东西
下一个ws

有没有人知道工作簿打开完成后是否有运行的事件?或者有什么其他建议可以实现这一点?

解决方案

将代码放在Workbook_Activate事件中。它发生在开放事件之后。

  Private Sub Workbook_Activate()
'代码到这里
End Sub


I want to run a VBA macro AFTER the workbook has finished opening. I tried to use workbook_open but this runs before the workbook has finished opening. This doesn't work for me as I need to loop through each sheet like so...

Private Sub Workbook_Open()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
'do stuff on each sheet
Next ws

End Sub

Does anyone know if there is an event which runs once the workbook has finished opening? Or have any other suggestions on how I can achieve this?

解决方案

Put your code in the Workbook_Activate event. It happens after the Open event.

Private Sub Workbook_Activate()
    ' Code goes here
End Sub

这篇关于VBA事件:在使用workbook_open运行代码之前加载工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 07:33