View Single Post
 
Old 04-14-2018, 04:47 AM
vicmar vicmar is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Aug 2017
Posts: 24
vicmar is on a distinguished road
Default Auto Hyperlink PDF files

Hi everyone,

I found a VBA code to make pdf auto hyperlink but my problem is I want the filename that will display is data in my excel not the filename of the PDF.

Example:
Column A
aaa1
aaa2
aaa3

the hyperlink you should insert in column a.

here is the code:

Sub AddHyperlink()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer

'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("\\server\folder\")
i = 2
'loops through each file in the directory
For Each objFile In objFolder.Files
'select cell
Range(Cells(i + 1, 1), Cells(i + 1, 1)).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
objFile.Path, _
TextToDisplay:=objFile.Name
i = i + 1
Next objFile
End Sub

thank you in advance!
Reply With Quote