VBA对话框可以在不同的工作簿中选择范围 [英] VBA Dialog box to select range in different workbook
问题描述
我想允许用户选择可能在不同工作簿中的范围。
I want to allow a user to select a range that is likely to be in a different workbook.
我尝试用inputbox(,键入:= 8)这样做,它可以在工作簿中选择数据,但拒绝允许我选择一个范围不同的工作簿
I have attempted to do this with inputbox("",type:=8) which works to select data in the workbook but refuses to allow me to select a range in a different workbook.
因此,我想要一个允许我执行此任务的对话框。
Hence I would like a dialog box that allows me to perform this task.
推荐答案
由于我是免费的,我为您创造了一个例子
Since I was free, I created an example for you
创建一个 Userform
并放置一个 ComboBox
,A RefEdit
控制和一个标签
Create a Userform
and place a ComboBox
, A RefEdit
Control and a Label
接下来将此代码粘贴到Userform中
Next paste this code in the Userform
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
这是运行Userform时获得的
This is what you get when you run the Userform
这篇关于VBA对话框可以在不同的工作簿中选择范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!