【问题标题】:copyfile excel vba path error复制文件excel vba路径错误
【发布时间】:2014-12-04 10:04:53
【问题描述】:

这里有什么问题:

辩护:

            Dim fso As Object, f As Object, ff As Object, f1 As Object
            Dim new_des As Object
            Application.ScreenUpdating = False
            Set fso = CreateObject("Scripting.FileSystemObject")
            Set f = fso.Getfolder("C:\test\new")
            Set ff = f.Files

            For Each f1 In ff......

            ....Set new_des = fso.Getfolder("C:\test\new\old" & "\" & f1).....

            ......FileCopy f1, new_des....

我有运行时错误 75 path not find to 'Set new_des.....' 路径在那里 “f1”正在保存文件

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    ff 是一个Files 集合,其中的每个f1 都是一个文件,所以

     fso.Getfolder("C:\test\new\old" & "\" & f1)
    

    在一个无效的文件路径上尝试GetFolder,因为它需要一个目录路径。

    您需要将完整路径字符串指向FileCopy

    【讨论】:

      【解决方案2】:

      我将 new_des 声明为字符串并且: new_des = ("C:\test\new\old") 然后我做了: FileCopy (f & f1), (new_des & f1)

      【讨论】:

        【解决方案3】:

        复制所有文件使用:

        fso.CopyFolder "C:\test\new", "C:\test\new\old" 'from new to old
        

        或者如果你想在你的代码中做,使用BuildPath()将文件夹与文件连接起来,GetFileName()得到f1的文件名并定义new_des as String来保存生成的路径:

        dim new_des as String
        new_des = fso.BuildPath("C:\test\new\old\", fso.GetFileName(f1))
        

        【讨论】:

          猜你喜欢
          • 2016-03-17
          • 2017-04-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-11-25
          • 1970-01-01
          • 1970-01-01
          • 2018-11-14
          相关资源
          最近更新 更多