有人可以告诉我我在做什么错,我正在尝试导出文件,如果该文件存在以将重复项添加到文件末尾,我似乎无法使其正常工作
Dim FilePath As String
Dim FileName As String
Dim MyDate As String
Dim megalist As String
Dim FileCopy As String
Dim copy As String
copy = " Duplicate"
FilePath = "Q:\RADIOLOGY\ADMINISTRATION\DATA\CT DISTRIBUTION\PAY ROLL\"
MyDate = Format(Date, "MM-DD-YYYY")
megalist = " Megalist"
FileName = FilePath & MyDate & megalist
FileCopy = FilePath & MyDate & megalist & copy
If Dir(FilePath) <> MyDate & Report Then
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FileName
Else
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FileCopy
End If
End Sub
答案 0 :(得分:1)
请参阅以下答案以生成您的FileName。
https://stackoverflow.com/a/31706252/1684486
然后只需使用ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FileName
EDiT 在您的情况下:
FilePath = "Q:\RADIOLOGY\ADMINISTRATION\DATA\CT DISTRIBUTION\PAY ROLL\"
MyDate = Format(Date, "MM-DD-YYYY")
megalist = " Megalist"
FileName = GetNextAvailableName(FilePath & MyDate & megalist)
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FileName
当然,您需要将GetNextAvailableName
函数从该答案复制到项目中的公共模块。