Excel精英培训网

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

[已解决]想在最后一句前加一个判断当前文件是否存在,如何写呀?

[复制链接]
发表于 2013-7-19 14:43 | 显示全部楼层 |阅读模式
原代码如下
p = ThisWorkbook.Path & "\"
        d = Format(Date, "yyyy年mm月dd日")
        f = p & "新建 Microsoft Word 文档.aoc"
        f2 = p & "2013" & s & ".doc"
        FileCopy f, f2
现在想在最后一句前加一个判断当前文件是否存在,路径和文件名是变量f2,用变量如何写呀?
最佳答案
2013-7-19 14:51
判断文件夹是否存在

Sub FileExist_Dir()
Dim strFile As String
   
    strFile = ThisWorkbook.Path & "\test.xls"
    If Dir(strFile) = "" Then
        MsgBox strFile & " does not Exists"
    Else
        MsgBox strFile & " Exist"
    End If
End Sub
发表于 2013-7-19 14:51 | 显示全部楼层    本楼为最佳答案   
判断文件夹是否存在

Sub FileExist_Dir()
Dim strFile As String
   
    strFile = ThisWorkbook.Path & "\test.xls"
    If Dir(strFile) = "" Then
        MsgBox strFile & " does not Exists"
    Else
        MsgBox strFile & " Exist"
    End If
End Sub
回复

使用道具 举报

 楼主| 发表于 2013-7-19 14:57 | 显示全部楼层
wayy 发表于 2013-7-19 14:51
判断文件夹是否存在

Sub FileExist_Dir()

噢,dir中是变量不要再加“”了,我试试
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-30 04:00 , Processed in 0.328689 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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