[code here]

  • Hi I am Lokesh from Delhi India. I was using below macro in my previous laptop with window 7, adobe reader as well MS office 7, but when i moved my data in new laptop with window 10, adobe acrobat as well as MS office 7, but it's not working here and i am facing the error as"could not create PDF file" any one help me plzzzz.




    Public Sub PDFAllSheets()

    r = 2
    Do
    If Sheets("Sheet2").Cells(r, 1) <> "" Then
    Application.StatusBar = "Processing salary slip: " & Sheets("Sheet2").Cells(r, 2)
    Range("J3:J4") = Sheets("Sheet2").Cells(r, 1)
    ActiveSheet.Calculate
    DoEvents

    PDFActiveSheet
    End If

    r = r + 1
    DoEvents
    Loop Until Sheets("Sheet2").Cells(r, 1) = ""

    Application.StatusBar = False

    End Sub

    Public Sub PDFActiveSheet()

    Dim ws As Worksheet
    Dim strPath As String
    Dim myFile As Variant
    Dim strFile As String

    On Error GoTo errHandler

    Set ws = ActiveSheet

    'enter name and select folder for file
    ' start in current workbook folder
    strFile = Replace(Replace(ws.Name, " ", ""), ".", "_") _
    & "_" _
    & Format(Now(), "yyyymmdd\_hhmm") _
    & ".pdf"
    strFile = ThisWorkbook.Path & "" & strFile

    'myFile = Application.GetSaveAsFilename _
    (InitialFileName:=strFile, _
    FileFilter:="PDF Files (*.pdf), *.pdf", _
    Title:="Select Folder and FileName to save")

    myFile = ThisWorkbook.Path & "" & Range("b10") & "_" & Range("b11") & ".pdf"

    'If myFile <> "ture" Then
    ws.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:=myFile, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False

    'MsgBox "PDF file has been created."
    'End If

    exitHandler:
    Exit Sub
    errHandler:
    MsgBox "Could not create PDF file"
    Resume exitHandler


    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!