Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 10536|回复: 2

[已解决]求教:VBA中FileCopy用法

[复制链接]
发表于 2015-4-28 17:05 | 显示全部楼层 |阅读模式
下面怎么代码运行为什么会出错?问题出在哪?
Sub 复制()
  FileCopy ThisWorkbook.Path & "\3.xlsx"
End Sub
最佳答案
2015-4-28 17:12
Sub test()
    Dim SourceFile, DestinationFile

    SourceFile = "c:\1.txt"    ' 指定源文件名。
    DestinationFile = "d:\1.txt"    ' 指定目的文件名。

    FileCopy SourceFile, DestinationFile    ' 将源文件的内容复制到目的文件中。
End Sub



这是帮助实例。
请根据你的实际情况,分别改成你自己的源文件名目的文件名
捕获.JPG
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2015-4-28 17:12 | 显示全部楼层    本楼为最佳答案   
Sub test()
    Dim SourceFile, DestinationFile

    SourceFile = "c:\1.txt"    ' 指定源文件名。
    DestinationFile = "d:\1.txt"    ' 指定目的文件名。

    FileCopy SourceFile, DestinationFile    ' 将源文件的内容复制到目的文件中。
End Sub



这是帮助实例。
请根据你的实际情况,分别改成你自己的源文件名目的文件名
回复

使用道具 举报

发表于 2015-4-28 17:14 | 显示全部楼层
FileCopy Statement


Office 2013  




Other Versions  








Last modified: December 06, 2011

Applies to: Office 2013 | VBA

Copies a file.

Syntax

FileCopy  source,  destination  

The FileCopy statement syntax has these named arguments:






Part


Description


source  

Required. String expression that specifies the name of the file to be copied. The source may include directory or folder, and drive.


destination  

Required. String expression that specifies the target file name. The destination may include directory or folder, and drive.

看帮助中的说明,两个参数必须有。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-24 10:54 , Processed in 0.365157 second(s), 12 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表