Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 将网站作为文本的单元格更改为链接(不使用=超链接功能)_Vba_Excel_Hyperlink - Fatal编程技术网

Vba 将网站作为文本的单元格更改为链接(不使用=超链接功能)

Vba 将网站作为文本的单元格更改为链接(不使用=超链接功能),vba,excel,hyperlink,Vba,Excel,Hyperlink,我为一家公司创建了一个用户表单,用于输入首选产品,其中包括该产品的网站。我将其设置为只将网站作为普通文本输入,但Excel中在单元格包含网站时自动注册的功能并没有将文本转换为活动超链接。 我可以从Tim Williams那里获得有关堆栈溢出的帮助,以创建超链接,但是=hyperlink函数处理的内容与www.google.com不同,可以使用更多代码来解决,但如果可能的话,我更愿意使用更少的代码 如果我双击单元格(没有=超链接),好像要添加文本,然后退出单元格,则链接会变成超链接 我需要什么VB

我为一家公司创建了一个用户表单,用于输入首选产品,其中包括该产品的网站。我将其设置为只将网站作为普通文本输入,但Excel中在单元格包含网站时自动注册的功能并没有将文本转换为活动超链接。 我可以从Tim Williams那里获得有关堆栈溢出的帮助,以创建超链接,但是=hyperlink函数处理的内容与www.google.com不同,可以使用更多代码来解决,但如果可能的话,我更愿意使用更少的代码

如果我双击单元格(没有=超链接),好像要添加文本,然后退出单元格,则链接会变成超链接

我需要什么VBA代码才能将在文本框中输入并通过用户表单提交的数据转换为工作表单元格中的超链接

下面是我目前的代码

Private Sub ComboBoxDivision_Change()

Me.ComboBoxSpecsNumber = ""
Me.ComboBoxSpecsName = ""
Select Case Me.ComboBoxDivision
    Case "DIVISION 02 - EXISTING CONDITIONS"
    Me.ComboBoxSpecsNumber.RowSource = "D02_Number"
    Me.ComboBoxSpecsName.RowSource = "D02_Name"

    Case "DIVISION 03 - CONCRETE"
    Me.ComboBoxSpecsNumber.RowSource = "D03_Number"
    Me.ComboBoxSpecsName.RowSource = "D03_Name"

    Case "DIVISION 04 - MASONRY"
    Me.ComboBoxSpecsNumber.RowSource = "D04_Number"
    Me.ComboBoxSpecsName.RowSource = "D04_Name"    
End Select
End Sub

Private Sub ComboBoxSpecsNumber_Change()
Application.EnableEvents = False
  With ComboBoxSpecsNumber
    ComboBoxSpecsName.ListIndex = .ListIndex
  End With
  Application.EnableEvents = True
End Sub

Private Sub ComboBoxSpecsName_Change()
Application.EnableEvents = False
  With ComboBoxSpecsName
    ComboBoxSpecsNumber.ListIndex = .ListIndex
  End With
  Application.EnableEvents = True
End Sub

Private Sub SubmitButton_Click()
If Me.ComboBoxDivision.Value = "" Then
MsgBox "Please select a Division.", vbExclamation, "Product_Information_Form"
Me.ComboBoxDivision.SetFocus
Exit Sub
End If
If Me.ComboBoxSpecsNumber.Value = "" Then
MsgBox "Please select a Specs Number or Name.", vbExclamation, "Product_Information_Form"
Me.ComboBoxSpecsNumber.SetFocus
Exit Sub
End If
If Me.ComboBoxSpecsName.Value = "" Then
MsgBox "Please select a Specs Name or Name.", vbExclamation, "Product_Information_Form"
Me.ComboBoxSpecsName.SetFocus
Exit Sub
End If

Sub AddLink(c As Range, text As String)
    If Len(text) > 0 Then
        c.Formula = "=HYPERLINK(""" & text & """)"
    Else
        c.Value = ""
    End If
End Sub

Dim RowCount As Long
RowCount = Worksheets("FormData").Range("A1").CurrentRegion.Rows.Count
With Worksheets("FormData").Range("A1")
.Offset(RowCount, 0).Value = Me.ComboBoxDivision.Value
.Offset(RowCount, 1).Value = Me.ComboBoxSpecsNumber.Value
.Offset(RowCount, 2).Value = Me.ComboBoxSpecsName.Value
AddLink .Offset(RowCount, 3), Me.TextBox_Website_Link.Value
.Offset(RowCount, 4).Value = Format(Now, "yyyy.mm.dd hh:mm:ss")
End With

Select Case Me.ComboBoxDivision
Case "DIVISION 02 - EXISTING CONDITIONS"
Dim LastRow As Long, ws As Worksheet
Set ws = Sheets("Div-02")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
ws.Range("a" & LastRow).Value = Me.ComboBoxSpecsNumber.Value
ws.Range("b" & LastRow).Value = Me.ComboBoxSpecsName.Value
AddLink ws.Range("c" & LastRow), Me.TextBox_Website_Link.Value

Case "DIVISION 03 - CONCRETE"
Set ws = Sheets("Div-03")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
ws.Range("a" & LastRow).Value = Me.ComboBoxSpecsNumber.Value
ws.Range("b" & LastRow).Value = Me.ComboBoxSpecsName.Value
AddLink ws.Range("c" & LastRow), Me.TextBox_Website_Link.Value

Case "DIVISION 04 - MASONRY"
Set ws = Sheets("Div-04")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
ws.Range("a" & LastRow).Value = Me.ComboBoxSpecsNumber.Value
ws.Range("b" & LastRow).Value = Me.ComboBoxSpecsName.Value
AddLink ws.Range("c" & LastRow), Me.TextBox_Website_Link.Value


End Select

Unload Product_Information_Form
Start_Form.Show

End Sub

是的,我知道这一点,但作为VBA的新手,我仍然不完全理解。有人指出我的代码哪里错了,这有助于我更快地了解我的具体问题。