VBS从链接保存文件 [英] VBS Save File From Link

查看:64
本文介绍了VBS从链接保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以帮助我.

I wonder whether someone can help me please.

我想使用

I wanting to use this solution in a script I'm trying to put together, but I'm a little unsure about how to make a change which needs to be made.

您将在解决方案中看到打开的文件类型是Excel,并且确实将其保存为Excel.但是我要打开和保存的文件是.docx和.dat(Dragon软件使用的)文件的混合物.

You'll see in the solution that the file type which is opened is a Excel and indeed it's saved as such. But I the files I'd like to open and save are a mixture of .docx and .dat (Used by Dragon software) files.

请问有人可以告诉我,有什么方法可以修改代码,以便它打开并以Excel工作簿以外的文件类型保存文件.

Could someone possible tell me please is there a way by which I can amend the code so it opens and saves the files in file types other than Excel workbooks.

此问题背后的原因,因为我当前正在使用一个脚本,该脚本从给定文件夹在Excel电子表格中创建文件列表.对于每个检索到的文件,都有一个超链接,我想在其中添加功能,以便用户复制文件并将其保存到他们选择的位置.

The reason behind this question because I'm currently using a script which creates a list of files in a Excel spreadsheet from a given folder. For each file that is retrieved there is a hyperlink, which I'd like to add fucntionality to which enables the user to copy the file and save it to a location of their choice.

为了帮助这是我用来创建文件列表的代码.

To help this is the code which I use to create the list of files.

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

非常感谢和问候

克里斯

推荐答案

Miguel提供了一个出色的解决方案,该解决方案在最初的测试中似乎可以100%起作用.但是,正如您从帖子末尾的评论中看到的那样,当用户取消操作时存在一些问题,因此我在此

Miguel provided a fantastic solution which on initial testing appeared to work 100%. But as you will see from the comments at the end of the post there were some issues when the user cancelled the operation, so I made another post at this link where the problems were ironed out. Many thanks and kind regards. Chris

这篇关于VBS从链接保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆