VBA修剪一个对象与string中的另一个对象(FSO.Getfolder相关)基本上结束与文件的相对path

我正在build立一个目录中的文件索引。 第1列与文件夹名称,第2列与文件名

我设法得到实际的文件名和超链接的文件名已经。 但是我列出了列1中文件的path,使用包含子文件夹的相对path出现问题。

说我有以下文件夹:“C:\ users \ ME \ Documents”在该文件夹中有许多子文件夹。

我想实现的是一个string列出实际的子文件夹的path。 例:

"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(".")返回正是我想从第一个string中删除!

所以我基本上想写一个脚本说:

Cells(i + ROW_FIRST - 1, 1) = objFolder.Name - objFSO.Getfolder(".")

但是我需要帮助,因为这个命令显然不起作用。

这可能有一个完全不同的方法,但由于我的macros已经有很多代码,使用修剪或replace或类似将是最简单的?

编辑:我的脚本中还有一个名为“GetAllFolders”的函数。 也许我可以通过某种方式来实现我想要的string?

 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) 
Interesting Posts