【发布时间】:2020-12-12 22:35:39
【问题描述】:
如果可能,我想添加代码来检查“返回注释”中是否存在与 B1 具有相同文本值的文件(其中包含要成为的文件名)
Private Sub CommandButton1_Click()
Dim NameofWorkbook As String
NameofWorkbook = "RN" & Range("B1")
MyMsg = NameofWorkbook + " " & "saved to return note folder"
'Create and assign variables
Dim saveLocation As String
saveLocation = "S:\Office information\Returns\Return Notes\" + NameofWorkbook
'Save Active Sheet(s) as PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=saveLocation
MsgBox MyMsg
End Sub
工作代码(感谢 Romulax):
Private Sub CommandButton1_Click()
Dim NameofWorkbook As String
Dim levSave As String
NameofWorkbook = "RN" & Trim(Range("B1"))
MyMsg = NameofWorkbook + " " & "saved to return note folder"
'Create and assign variables
Dim saveLocation As String
saveLocation = "S:\Office information\Returns\Return Notes\" & NameofWorkbook
lenSave = saveLocation & ".pdf"
If Len(Dir(lenSave)) = 0 Then
MsgBox "File does not exist"
'Do stuff
'Save Active Sheet(s) as PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=saveLocation
MsgBox MyMsg
Else
MsgBox "Filename taken."
End If
End Sub
【问题讨论】:
标签: excel vba pdf duplicates