ComboBox 超链接

ComboBox Hyperlink

提问人:Semir Hasanovic 提问时间:10/10/2023 最后编辑:JohnMSemir Hasanovic 更新时间:10/10/2023 访问量:39

问:

我是编程新手,我需要在Excel中完成一个项目

如何使用户窗体根据ComboBox的选择打开超链接?

这是我的代码。有人可以向我解释一下该怎么做吗?

    Private Sub UserForm_Click()
    
    End Sub
    
    Private Sub UserForm_Initialize()
    
    With Historie.ComboBox1
    
        .AddItem "xxx"
        .AddItem "yyy"
        .AddItem "WWW"
       
    
    End With
    
    End Sub
    
    Private Sub Historie_Change()
        Select Case Me.Historie.Value
            Case "xxx"
                Me.CommandButton1.Caption = "Zum Update"
                Me.CommandButton1.Tag = "https://www.google.com"
                
            Case "yyy"
                Me.CommandButton1.Caption = "Zum Update"
                Me.CommandButton1.Tag = "https://www.google.com"
                
            Case "WWW"
                Me.CommandButton1.Caption = "Zum Update"
                Me.CommandButton1.Tag = "https://www.google.com"
        
    End Sub
    
    Private Sub CommandButton1_Click()
       
        If Me.CommandButton1.Tag <> "" Then
            ThisWorkbook.FollowHyperlink Address:=Me.CommandButton1.Tag
        End If
    
    End Sub

我环顾四周很久,连ChatGPT都没能给我答案。请帮忙。

Excel VBA 超链接 用户窗体

评论

0赞 CHill60 10/10/2023
什么?Historie
0赞 Semir Hasanovic 10/10/2023
它是用户窗体的名称
2赞 CHill60 10/10/2023
您发布的代码似乎认为它是组合框 - - 表单没有这样的事件,表单也没有值。尝试调用 ComboBox 并将 Initilise 更改为 即删除Historie_ChangeHistorieWith Historie.ComboBox1

答:

1赞 VBasic2008 10/10/2023 #1

组合框超链接

  • 您错误地引用了组合框。
  • 此外,Select 语句处于“正在构建中”。
Private Sub ComboBox1_Change()
    With Me.CommandButton1
        .Caption = "Zum Update"
        Select Case Me.ComboBox1.Value
            Case "xxx": .Tag = "https://www.google.com"
            Case "yyy": .Tag = "https://www.google.com"
            Case "www": .Tag = "https://www.google.com"
            Case Else: .Tag = "": .Caption = "Kein Link"
        End Select
    End With
End Sub

Private Sub UserForm_Initialize()
    With Me
        .ComboBox1.List = Array("xxx", "yyy", "www")
        .CommandButton1.Caption = "Keine Auswahl"
    End With
End Sub

Private Sub CommandButton1_Click()
    With Me.CommandButton1
        If .Tag <> "" Then ThisWorkbook.FollowHyperlink Address:=.Tag
    End With
End Sub

评论

0赞 Semir Hasanovic 10/10/2023
坦克你这么多!