我正在建立目录中文件的索引。第1列具有文件夹名称,第2列具有文件名
我已经设法获得了实际的文件名,并且已经超链接了文件名。但是我在使用包含子文件夹的相对路径在第1列中列出文件的路径时遇到了问题。
说我有以下文件夹:“ C:\ users \ ME \ Documents”在该文件夹中,有许多子文件夹。
我要实现的是一个字符串,该字符串列出了该实际子文件夹的路径。例子:
"C:\users\ME\Documents\Subfolder1\Subfolder2\CharlieSheen.pdf"
Column 1 (A5) = Subfolder1\Subfolder2\
Column 2 (B5) = CharlieSheen.pdf
正如我说的,我可以控制第2列。
我正在使用的脚本是
Private Function GetAllFiles(ByVal strpath As String, _
ByVal intRow As Integer, ByRef objFSO As Object) As Integer
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer`
i = intRow - ROW_FIRST + 1
Set objFolder = objFSO.Getfolder(strpath)
For Each objFile In objFolder.Files
'print file path
Cells(i + ROW_FIRST - 1, 1) = objFolder.Name
i = i + 1
Next objFile
GetAllFiles = i + ROW_FIRST - 1
End Function
我发现改变
Cells(i + ROW_FIRST - 1, 1) = objFolder.Name
进入Cells(i + ROW_FIRST - 1, 1) = objFSO.Getfolder(".")
返回正是我想从第一个字符串中删除!
所以我基本上想写一个脚本,说:
Cells(i + ROW_FIRST - 1, 1) = objFolder.Name - objFSO.Getfolder(".")
但是我需要帮助,因为该命令显然不起作用。
可能有完全不同的方法,但是由于我的宏已经有很多代码,使用Trim或Replace或类似方法最简单?
编辑:我的脚本中还有一个名为“ GetAllFolders”的函数。也许我可以通过某种方式调用它来实现我想要的字符串?
Private Sub GetAllFolders(ByVal strFolder As String, _
ByRef objFSO As Object, ByRef intRow As Integer)
Dim objFolder As Object
Dim objSubFolder As Object
'Get the folder object
Set objFolder = objFSO.GetFolder(strFolder)
'loops through each file in the directory and
'prints their names and path
For Each objSubFolder In objFolder.subfolders
intRow = GetAllFiles(objSubFolder.Path, _
intRow, objFSO)
'recursive call to to itsself
Call GetAllFolders(objSubFolder.Path, _
objFSO, intRow)
Next objSubFolder
End Sub
关于什么
Cells(i + ROW_FIRST - 1, 1) = Replace$(objFolder.Name, CStr(objFSO.Getfolder(".")), vbNullString)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句