我想允许用户选择可能位于不同工作簿中的范围。
我尝试使用 inputbox("",type:=8) 来执行此操作,它可以选择工作簿中的数据,但不允许我在不同的工作簿中选择范围。
因此我想要一个允许我执行此任务的对话框。
由于我有空,我为您创建了一个示例
创建一个Userform
并放置一个ComboBox
, A RefEdit
控制和一个Label
接下来将此代码粘贴到用户表单中
Private Sub UserForm_Initialize()
Dim wb As Workbook
'~~> Get the name of all the workbooks in the combobox
For Each wb In Application.Workbooks
ComboBox1.AddItem wb.Name
Next
ComboBox1 = ActiveWorkbook.Name
End Sub
'~~> This lets you toggle between all open workbooks
Private Sub Combobox1_Change()
If ComboBox1 <> "" Then Application.Workbooks(ComboBox1.Text).Activate
Label1.Caption = "": RefEdit1 = ""
End Sub
'~~> And this lets you choose the relevant range
Private Sub RefEdit1_Change()
Label1.Caption = ""
If RefEdit1.Value <> "" Then _
Label1.Caption = "[" & ComboBox1 & "]" & RefEdit1
End Sub
这是运行用户表单时得到的结果
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)