PDF deducted as opened

kamranyd

Board Regular
Joined
Apr 24, 2018
Messages
142
Office Version
  1. 2021
Platform
  1. Windows
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.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,214,830
Messages
6,121,839
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top