【发布时间】:2015-04-17 06:22:21
【问题描述】:
我想知道是否有人可以帮助我。
我想在我尝试组合的脚本中使用this 解决方案,但我有点不确定如何进行需要进行的更改。
您会在解决方案中看到打开的文件类型是 Excel,并且确实是这样保存的。但我要打开和保存的文件是 .docx 和 .dat(由 Dragon 软件使用)文件的混合。
谁能告诉我,有没有一种方法可以让我修改代码,以便它以 Excel 工作簿以外的文件类型打开和保存文件。
这个问题背后的原因是因为我目前正在使用一个脚本,该脚本在给定文件夹的 Excel 电子表格中创建文件列表。对于检索到的每个文件,都有一个超链接,我想为其添加功能,使用户能够复制文件并将其保存到他们选择的位置。
为了帮助解决这个问题,我使用了代码来创建文件列表。
Public Sub ListFilesInFolder(SourceFolder As Scripting.folder, IncludeSubfolders As Boolean)
Dim LastRow As Long
Dim fName As String
On Error Resume Next
For Each FileItem In SourceFolder.Files
' display file properties
Cells(iRow, 3).Formula = iRow - 12
Cells(iRow, 4).Formula = FileItem.Name
Cells(iRow, 5).Formula = FileItem.Path
Cells(iRow, 6).Select
Selection.Hyperlinks.Add Anchor:=Selection, Address:= _
FileItem.Path, TextToDisplay:="Click Here to Open"
iRow = iRow + 1 ' next row number
With ActiveSheet
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End With
For Each Cell In Range("C13:F" & LastRow) ''change range accordingly
If Cell.Row Mod 2 = 1 Then ''highlights row 2,4,6 etc|= 0 highlights 1,3,5
Cell.Interior.Color = RGB(232, 232, 232) ''color to preference
Else
Cell.Interior.Color = RGB(141, 180, 226) 'color to preference or remove
End If
Next Cell
Next FileItem
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
ListFilesInFolder SubFolder, True
Next SubFolder
End If
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
End Sub
非常感谢和亲切的问候
克里斯
【问题讨论】:
标签: excel excel-2013 vba