我正在为我的同事创建一个宏。他们每天都会收到一个文件,并且在一天结束时必须将某些信息复制到另一个工作簿中。宏是负责复制的。我想要一个带有组合框弹出窗口的用户表单,其中包含当前打开的工作簿列表,以便它知道要从哪个文件复制。如何设置它以便在那里进行的选择设置具有该选择的工作簿变量?
我想做的是:
Sub CopySub()
Dim wb As Workbook
UserForm1.Show
Set wb = Workbooks(ComboBox1.Value)
....Rest of Copy and Paste Code
下面是用户表单的代码:
Private Sub OK_Click()
'Take user selection and continue copy and paste code
UserForm1.Hide
End Sub
Private Sub Cancel_Click()
'Cancel everything, end all code
End
End Sub
Private Sub UserForm_Activate()
'Populate list box with names of open workbooks.
Dim wb As Workbook
For Each wb In Workbooks
ComboBox1.AddItem wb.Name
Next wb
End Sub