Convert Word Doc to PDF

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ghaleon
    New Member
    • Aug 2013
    • 28

    Convert Word Doc to PDF

    I finally finished my word doc. But now I was told to create a PDF instead u.u

    I tried this code:

    Code:
    Dim Word_App As Word.Application
    Set Word_App = New Word.Application
    
    'Create and fill the word document.
    
    'Save the document as PDF
    Word_App.ActiveDocument.ExportAsFixedFormat
    OutputFileName:=Replace(strPath, ".rtf", "") & " - " &
    vtCartas(iMarcaCartasIndividuais).strMatricula & ".pdf", _
    ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _
    OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, TO:=1, _
    Item:=wdExportDocumentContent, IncludeDocProps:=True,
    KeepIRM:=True, CreateBookmarks:=wdExportCreateNoBookmarks,
    DocStructureTags:=True, BitmapMissingFonts:=True, _
    UseISO19005_1:=False
    But I'm getting this error:
    Object Variable or With Block variable not set
    Last edited by Rabbit; Sep 12 '13, 03:52 PM. Reason: Fixed code tags
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I have to assume this code was not a direct copy and paste because you are missing line continuation characters. But after I put those in and change the path to one on my computer, the code runs just fine for me.

    Make sure you didn't unset Word_App somewhere above that line.

    Comment

    • Ghaleon
      New Member
      • Aug 2013
      • 28

      #3
      The Strange thing is that if I try this code:
      Code:
      Word_App.ActiveDocument.SaveAs filename:=strPath & "\doc1.doc"
      It works, it saves the document as a .doc

      but when I try to convert it to PDF it gives me the error =\

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Well, I don't know what else to try. It works fine for me after I fix the line continuation characters.

        Comment

        • Ghaleon
          New Member
          • Aug 2013
          • 28

          #5
          Code:
          '********************** WORD ****************************
          Private Word_App                    As Word.Application
          Private Word_Doc                    As Word.Document
          Private Word_Rtf_Doc                As Word.Document
          Private Word_Table                  As Word.Table
          Private Word_Range                  As Word.Range
          Private objRow                      As Row
          Private objCell                     As Cell
          Private sCellText                   As String
          Private Range                       As Range
          Private strPath                     As String
          Private iMarcaPaginas               As Integer
          Private iMarcaCartasIndividuais     As Integer
          Private strTempLogo                 As String
          '***************** END OF WORD ***************************
          
          
          Private Sub CreateDoc(strCarta As String)
              On Error GoTo Trata_Erros    
              Dim i                           As Integer
              Dim strDebito                   As String
              Dim strValor                    As String
              Dim strVlMulta                  As String
              Dim strVlSubTotal               As String
          
          
          strVlMulta = format(vtcJurosMultas(iLinha).cTotalTx, "#,##0.#0")
          strVlSubTotal = format(vtcJurosMultas(iLinha).cSubTotal, "#,##0.#0")
          
          With ActiveDocument.Content.Find.Execute FindText:="
          debito>", ReplaceWith:="" & strDebito, format:=True,
             Replace:=wdReplaceAll.Execute FindText:="<valor>",
             ReplaceWith:="" & strValor, format:=True,
             Replace:=wdReplaceAll.Execute FindText:="    <jurosmulta>",
             ReplaceWith:="" & strVlMulta, format:=True,              Replace:=wdReplaceAll.Execute FindText:="<total>",
             ReplaceWith:="" & strVlSubTotal, format:=True,
             Replace:=wdReplaceAll.Execute FindText:="<totalf>",
             ReplaceWith:="" & strVlSubTotal, format:=True,
             Replace:=wdReplaceAll
          End With
          
          Word_App.ActiveDocument.ExportAsFixedFormat OutputFileName:=Replace(strPath & "\doc1.doc",
          ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False,
          OptimizeFor:=wdExportOptimizeForPrint,Range:=wdExportAllDocument, From:=1, TO:=1, _
          Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True,CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:=True, _
          UseISO19005_1:=False
          Could you take a look and see if you find something wrong?
          Thanks.

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            If this is a direct copy and paste of your code, then you are missing line continuation characters at 42 and 43.

            Comment

            • Ghaleon
              New Member
              • Aug 2013
              • 28

              #7
              I'm using the continuation characters... Just deleted by mistake... Guess I'll have to find antoher way to make this conversion ;\

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                In that case, if that's your entire code, Word_App is never initialized anywhere, it's only declared.

                Comment

                • Ghaleon
                  New Member
                  • Aug 2013
                  • 28

                  #9
                  It's working now \o/ I had to install an Add-in of MS-Word. But now, the characteres are a little bit strange... It still letters and you're able to read it. But it's a little strange you know ? is there a way to fix it ?
                  I'm trying to find a way/command to renderize the font, but didn't find it yet.

                  Look:

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #10
                    We try to limit threads to one question each. Please create a new one for this question. As for the image, our firewalls block external storage sites, please upload the image to bytes instead.

                    Comment

                    Working...