我创建了一个表单,允许用户点击一个按钮,然后它允许您浏览和查找您的文档或任何内容,并将其作为链接提交给其他相关数据。我想知道如果他们是一种方式来允许用户使链接连接到充满多个文件的文件夹,而不需要手动执行它。这里是我的代码如下如何通过Excel中的vba表单链接文件
Private Sub AddPicture_Click()
Dim strFileToLink As String
'link name
lnkNm = InputBox("please enter link description")
Application.ScreenUpdating = False
strFileToLink = Application.GetOpenFilename _
(Title:="Please select an Evidence file to link to")
'Checking if file is selected.
If strFileToLink = "" Then
'Displaying a message if file not choosen in the above step.
MsgBox "No file selected.", vbExclamation, "Sorry"
'And exiting from the procedure.
Exit Sub
Else
'print link to sheet as a hyperlink.
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ActiveSheet
If ActiveSheet.Index >= 5 Then
.Hyperlinks.Add Anchor:=Cells(erow, 12), _
Address:=strFileToLink, _
ScreenTip:="Picture Link", _
TextToDisplay:=lnkNm
Else
.Hyperlinks.Add Anchor:=Cells(erow, 13), _
Address:=strFileToLink, _
ScreenTip:="Picture Link", _
TextToDisplay:=lnkNm
End If
End With
End If
End Sub
关于改进代码的意见,将不胜感激。谢谢
用户表单上的链接是什么意思?我很抱歉,我不明白您的要求 –
我希望用户窗体让用户抓住文件夹/文件,然后将链接放在Excel表单上。 – cfaidl05
那么你用上面的代码面临什么问题? –