如何使用用户窗体文本框和macros在工作簿单元格中创build超链接到硬盘驱动器文件

我有一个用户窗体使用文本框作为源添加到工作表上的数据。 这样做很简单:指定的单元格等于文本框的值。

我的一个专栏是用于链接到我的计算机上的文件夹的照片链接。 这是我卡住的地方,因为我可以将文件path添加到我的文本框的单元格,但它不是突出显示蓝色和下划线(不超链接)。 这是我想要自动化的东西。

谢谢你的时间家伙,这个团队字面上是我在网上find的最好的!

注意:正如你将在我的代码中看到的,我的文件夹path和文件格式将始终是相同的,文本框的值使所有的差异; “filepath”&userform.textbox.value&“.jpg”。 我喜欢这种方式有一些很好的理由,改变它并不是我的select。 build议和教育却受到追捧!

码:

With ws '.Unprotect Password:="password" .Cells(iRow, 1).Value = DRAFT1.PART2.Value .Cells(iRow, 2).Value = DRAFT1.LOC2.Value .Cells(iRow, 3).Value = DRAFT1.DESC2.Value .Cells(iRow, 5).Value = DRAFT1.QTY2.Value .Cells(iRow, 8).Value = DRAFT1.DATE2.Value .Cells(iRow, 9).Value = DRAFT1.POS2.Value .Cells(iRow, 10).Value = DRAFT1.TYPE2.Value .Cells(iRow, 11).Value = DRAFT1.COLOR2.Value .Cells(iRow, 12).Value = DRAFT1.FEATURES2.Value 'this is where I am having trouble .Cells(iRow, 13).Value = "C:\User\ttech\Desktop\EXCEL\PHOTOS\" & DRAFT1.PHOTO2.Value & ".jpg" 'I tried ActiveSheets.Hyperlink.Add(filepath...) 'And (filepath...).hyperlinks .Cells(iRow, 14).Value = DRAFT1.OTHERNAMES2.Value ' .Protect Password:="password" 

尝试这个

 .hyperlinks.add Anchor:= .Cells(iRow, 13), Address:= "C:\User\ttech\Desktop\EXCEL\PHOTOS\" & DRAFT1.PHOTO2.Value & ".jpg", TextToDisplay:= "C:\User\ttech\Desktop\EXCEL\PHOTOS\" & DRAFT1.PHOTO2.Value & ".jpg" 

不知道你如何尝试超链接添加,但它应该如上所述

你不需要活动工作表,如果它包含在你的