2016-03-24 30 views
2

Bir pdf dosyasının tüm yollarını ve etkin çalışma kitabını görüntüleyebilen bir kod ile çalışıyorum. Ancak sorun ayıklanan dosyalar köprülenmiyor, yani dosyaları doğrudan bu hücreye tıklandığında açamıyorum. Otomatik olarak köprünün herhangi bir yolu var mıdır, böylece tek tıklamayla dosyaları doğrudan excel'den açar. Aşağıda Otomatik Köprü ayıklanan dosyalar

kodudur:

Sub ReadFiles() 
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(Range("C1").Value) 

i = 1 
'loops through each file in the directory and prints their names and path 
For Each objFile In objFolder.Files 
If Right(objFile.Path, 3) = "pdf" Then 
    'print file path 
    Cells(i + 2, 13) = objFile.Path 
    i = i + 1 
End If 
Next objFile 
End Sub 

cevap

0

Bu işe çalışma sayfanızdaki adıyla "WorksheetName" yerine olmalıdır:

Sub ReadFiles() 
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(Range("C1").Value) 

i = 1 
'loops through each file in the directory and prints their names and path 
For Each objFile In objFolder.Files 
If Right(objFile.Path, 3) = "pdf" Then 
    'print file path 
    Cells(i + 2, 13) = objFile.Path 
    Sheets("WorksheetName").Hyperlinks.Add _ 
    Anchor:= Sheets("WorksheetName").Cells(i + 2, 13), _ 
    Address:= objFile.Path 
    i = i + 1 
End If 
Next objFile 
End Sub 
0

Eğer dosya yolu bu eklentiyi yazdırmak sonra: cells(i + 2,13).select ActiveCell.Hyperlinks.Add ActiveCell, ActiveCell

+0

Makroyu yavaşlatmaya eğilimli olduğundan VBA'da kod yazarken '.Select' işlevini kullanmaktan kaçınmak iyidir. – Jordan