VBA Dialog box to select range in different workbook

前端 未结 1 627
执念已碎
执念已碎 2020-12-01 13:33

I want to allow a user to select a range that is likely to be in a different workbook.

I have attempted to do this with inputbox(\"\",type:=8) which works to select

相关标签:
1条回答
  • 2020-12-01 13:56

    Since I was free, I created an example for you

    Create a Userform and place a ComboBox, A RefEdit Control and a Label

    enter image description here

    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
    

    This is what you get when you run the Userform

    enter image description here


    enter image description here


    enter image description here

    0 讨论(0)
提交回复
热议问题