Results 1 to 2 of 2

Thread: Run-time error 5121

  1. #1

    Thread Starter
    New Member Ali sharifi's Avatar
    Join Date
    Jul 2019
    Posts
    2

    Smile Run-time error 5121

    Hello;
    I'm trying to convert a PDF file with MSWORD.
    It's working fine, but some PDF files are broken, so they return an error.
    How can I handle this error?

    Name:  ff.png
Views: 68
Size:  6.3 KB


    Run-time error '5121':
    Sorry, we're having trouble converting your PDF to a Word document.


    My code:

    Code:
      On Error Resume Next
      
     path ="f:\"
     fileName = "test.pdf"
     wordFile = Replace(fileName, ".pdf", ".docx")
    
      Dim wdApp As Object
      Set wdApp = CreateObject("Word.Application")
      Dim wdDoc As Object
      myfile = path & fileName
      Set wdDoc = wdApp.Documents.Open(fileName:=myfile)
      wdApp.Visible = False
      wdApp.DisplayAlerts = wdAlertNone
      wdApp.ActiveDocument.SaveAs (path & wordFile)
      wdApp.Quit
      Set wdDoc = Nothing
      Set wdApp = Nothing
    Thank you very much

  2. #2

    Thread Starter
    New Member Ali sharifi's Avatar
    Join Date
    Jul 2019
    Posts
    2

    Re: Run-time error 5121

    By changing Error trapping settings I got it resolved.
    Tools->Options->General

    Break on unhandled errors

    Attachment 191683

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width