gpt4 book ai didi

excel - 用于在不同工作簿中选择范围的 VBA 对话框

转载 作者:行者123 更新时间:2023-12-01 19:16:54 25 4
gpt4 key购买 nike

我想允许用户选择可能位于不同工作簿中的范围。

我尝试使用 inputbox("",type:=8) 来执行此操作,它可以选择工作簿中的数据,但不允许我选择不同工作簿中的范围。

因此我想要一个允许我执行此任务的对话框。

最佳答案

由于我有空,我为您创建了一个示例

创建一个用户窗体并放置一个ComboBox、一个RefEdit控件和一个标签

enter image description here

接下来将此代码粘贴到用户表单中

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

这是运行用户表单时得到的结果

enter image description here

<小时/>

enter image description here

<小时/>

enter image description here

关于excel - 用于在不同工作簿中选择范围的 VBA 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18125650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com