简体   繁体   English

需要Excel VBA Workbook_open事件处理程序

[英]Excel VBA Workbook_open event handler required

I have reference data in columns A and B on Sheet2 of my WorkBook . 我在WorkBook Sheet2上的A和B列中有WorkBook I have a blank sheet - Sheet1 - which i need to fill from my database. 我有一张白纸 - Sheet1 - 我需要从我的数据库中填写。

I want to use Excel VBA to fill Sheet1 based on data in columns A and B in Sheet2 . 我想使用Excel VBA根据Sheet2中 A列和B列中的数据填充Sheet1

I use the reference data by. 我使用参考数据。

  • I populate values in column A in Sheet1 from DB. 我从DB填充Sheet1中的A列中的值。
  • I check if the values stored in sheet 1, column A exist in Sheet2 column A, 我检查Sheet2列A中是否存在第1页A列中存储的值,
  • If so, I populate into sheet 1 column B, the corresponding data i've found in Sheet2 column B. 如果是这样,我填入表1列B,我在Sheet2列B中找到相应的数据。
  • Open , do alt + F11 that will open the IDE. 打开 ,执行将打开IDE的alt + F11。
  • In the right hand window should see vba project and in brackets the name of the excel book you have open. 在右侧窗口中应该看到vba项目,并在括号中显示您打开的excel书的名称。
  • At the bottom of the list of sheets is an object called ThisWorkbook , right click it, and select View Code . 在工作表列表的底部是一个名为ThisWorkbook的对象,右键单击它,然后选择查看代码
  • At top of should see two combo boxes, right hand one should say General click on it and select Workbook from the list. 在顶部应该看到两个组合框,右手应该说一般点击它并从列表中选择Workbook

This should give you the following 这应该给你以下

 Private Sub Workbook_Open()

 End Sub

This is the event that is fired each time the work book is opened. 这是每次打开工作簿时触发的事件。 Now you will need to add code to reference the sheets in the workbook. 现在,您需要添加代码以引用工作簿中的工作表。

Here is some methods for how to reference sheets in vba Reference sheets . 以下是有关如何在vba 参考表中引用工作表的一些方法。 Next step will be to refer to the cells in the sheets see - > excel ranges as an example. 下一步将参考工作表中的单元格,参见 - > excel范围作为示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM