Code:
Sub SaveAsPDF()
Dim PathAndName As String
Dim Ans As Integer
PathAndName = Range("J1").Value
'If IsFileOpen("C:\Users\KYD\Desktop\111.pdf") Then
MsgBox "File already in use!"
Exit Sub
End If
If Dir(PathAndName) <> "C:\Users\KYD\Desktop" Then
Ans = MsgBox("File already exists. Overwrite?", vbQuestion + vbYesNo, "Overwrite?")
If Ans = vbNo Then Exit Sub
End If
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:=PathAndName, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
Rich (BB code):
Function IsFileOpen(filename As String)
Dim filenum As Integer, errnum As Integer
On Error Resume Next
filenum = FreeFile()
Open filename For Input Lock Read As #filenum
Close filenum
errnum = Err
On Error GoTo 0
Select Case errnum
Case 0
IsFileOpen = False
Case 70
IsFileOpen = True
Case Else
Error errnum
End Select
End Function
Hi, can anybody help me with these, these codes which shows warning that pdf file is open i press OK and if it is not open it will show warning that PDF already exit, want to OVERWRITE or NO.
i need some changes .
1st it should search file in folder and file name should be taken from cell whatever file name i type for search and if it is open it should warn me that file is open it should not be specific file searching in specific folder.
2nd File shall not be duplicate if it find duplicate it shall show me warning REPLACE or NO.
3rd if it is not duplicate than save as pdf taking name from 2 different cells.