Sviluppare funzionalita su Microsoft Office con VBA Errore in salvataggio file in pdf (via macro)

Login Registrati
Stai vedendo 8 articoli - dal 1 a 8 (di 8 totali)
  • Autore
    Articoli
  • #23903 Score: 0 | Risposta

    PMC77
    Partecipante
      18 pts

      Buongiorno a tutti!

      Ho un problema con la sub (che allego nel file .bas)...

      Mi da errore 424 nel momento in cui cerco di salvare il doc modificato in pdf

      Non capisco davvero dove sbaglio!

      #23904 Score: 0 | Risposta

      PMC77
      Partecipante
        18 pts

        Non mi lascia caricare il modulo...

         

        Sub CreaPDF()
           
            Dim oApp As Application
            Dim oDoc As DocumentInspector
           
            Dim FileDest As String
            Dim PathDest As String
           
            Dim FileOrig As String
            Dim PathOrig As String
           
            Dim Row As Integer
            Dim RowMax As Integer
                   
            Dim ShPECU As Worksheet
            Set ShPECU = ThisWorkbook.Worksheets("DatiPerInvioPECU")
                   
            'Ciclo sul Foglio PECU
            PathOrig = "Q:\"
            FileOrig = "lettera_ANAC_BookMarks.doc"
            PathOrig = PathOrig & FileOrig
            Row = 2
            RowMax = 150
            While Row <= RowMax And ShPECU.Range("A" & Row).Value <> ""
               
                'Per ogni riga genera un Pdf nella cartella corretta con i Dati Specifici (Tipo stampa Unione)
                Set wrd = CreateObject("Word.Application")
                wrd.Visible = True
                PathDest = "Q:\"
                FileDest = Left(ShPECU.Range("A" & Row).Value, 1) & "_" & ShPECU.Range("H" & Row).Value & "_" & ShPECU.Range("B" & Row).Value & "\lettera_ANAC.pdf"
                PathDest = PathDest & FileDest
                Set doc = wrd.Documents.Open(PathOrig)
                With doc
                    .Bookmarks("Fascicolo").Range.Text = ShPECU.Range("F" & Row).Value
                    .Bookmarks("Dirigente").Range.Text = ShPECU.Range("G" & Row).Value
                    .Bookmarks("FrasePECU").Range.Text = ShPECU.Range("e" & Row).Value
                   
                    ActiveDocument.ExportAsFixedFormat OutputFileName:= _
                        PathDest, ExportFormat:= _
                        wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
                        wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
                        Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
                        CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
                        BitmapMissingFonts:=True, UseISO19005_1:=False
                       
                End With
                         
                wrd.Quit
                Set wrd = Nothing
                Set doc = Nothing
                      
                'Incrementa la Riga
                Row = Row + 1
               
            Wend
        End Sub

        #23905 Score: 0 | Risposta

        Luca73
        Partecipante
          58 pts

          Ciao senza testare diventa difficile.

          l'unica cosa che mi lascia peplesso è la chiamata "ActiveDocument.ExportAsFixedFo...."

          manca un punto lì davanti? Oppure un "wrd."

          Così mi sembra che stai dando in pasto a excel un documento word...

          Ciao

          Luca

           

          #23906 Score: 0 | Risposta

          patel
          Moderatore
            51 pts

            Prima un .bas, poi il codice senza cliccare su (codice VBA), insomma ti ci metti d'impegno a voler perdere tempo, non sei novello su questo forum.

            #23907 Score: 0 | Risposta

            PMC77
            Partecipante
              18 pts

              Allora...

              Intanto grazie a Luca73!

              Ero arrivato anche io alla mancanza di wrd. davanti all'istruzione che genera il pdf

              in allegato trovate tutto

              Allegati:
              You must be logged in to view attached files.
              #23910 Score: 0 | Risposta

              Luca73
              Partecipante
                58 pts

                Ciao Rimane comunque difficile in quanto il file word non c'è.

                Penso di aver risolto l'arcano:

                hai copiato un pezzo di macro da word ad excel.

                Tale pezzo di macro contiene delle variabili che sono proprie di word (ad esempio wdExportFormatPDF) tali costanti tipiche di word non esistono in excel. e pertanto non sono valorizzate mentre lo sono se sei in word.

                mi ci sono scontrato anche io...

                Secondo me ci sono due soluzioni: la prima è capire qual'è il loro valore in word e sostituirle con il loro valore.

                la secondo è provare a porgli davati il qualificatore di word o trovare un modo per farle valorizzare in maniera corretta

                Ciao

                Luca

                 

                 

                 

                 

                #23916 Score: 0 | Risposta

                albatros54
                Moderatore
                  89 pts

                  sicuramente il proble è perche manca il riferimento alla libreria di word. Comunque, col codice che ti posto il tutto funziona, naturalmente devi sostituire i riferimenti che ho messo per verificare il codice, sostituisci i riferimenti e fai sapere.

                  Sub CreaPDF()
                  'late binding
                  '    Dim oApp As Application
                  '    Dim oDoc As DocumentInspector
                      Dim wrd As Object
                      Dim FileDest As String
                      Dim PathDest As String
                  
                      Dim FileOrig As String
                      Dim PathOrig As String
                  
                      Dim Row As Integer
                      Dim RowMax As Integer
                  
                      Dim ShPECU As Worksheet
                      Set ShPECU = ThisWorkbook.Worksheets("DatiPerInvioPECU")
                  
                      'Ciclo sul Foglio PECU
                      PathOrig = "C:\Users\Albatros\Desktop\stampaunione\"
                      FileOrig = "moduloa.docx"
                      PathOrig = PathOrig & FileOrig
                      Row = 2
                      RowMax = 150
                      While Row <= RowMax And ShPECU.Range("A" & Row).Value <> ""
                  
                          'Per ogni riga genera un Pdf nella cartella corretta con i Dati Specifici (Tipo stampa Unione)
                          Set wrd = CreateObject("Word.Application")
                          wrd.Visible = True
                          PathDest = "C:\Users\Albatros\Desktop\stampaunione\"
                          FileDest = "lettera_ANAC" & ".pdf"    'Left(ShPECU.Range("A" & Row).Value, 1) & "_" & ShPECU.Range("H" & Row).Value & "_" & ShPECU.Range("B" & Row).Value & "\lettera_ANAC"
                          'PathDest = PathDest & FileDest
                          Set Doc = wrd.Documents.Open(PathOrig)
                          With Doc
                              .Bookmarks("Fascicolo").Range.Text = ShPECU.Range("F" & Row).Value
                              .Bookmarks("Dirigente").Range.Text = ShPECU.Range("G" & Row).Value
                              .Bookmarks("FrasePECU").Range.Text = ShPECU.Range("e" & Row).Value
                             
                              Doc.ExportAsFixedFormat PathDest & FileDest, ExportFormat:=17, OpenAfterExport:=True
                  
                          End With
                  
                          wrd.Quit
                          Set wrd = Nothing
                          Set Doc = Nothing
                  
                          'Incrementa la Riga
                          Row = Row + 1
                  
                      Wend
                  
                  End Sub
                  

                   

                  Qual è il punto di avere gusti diversi, se non mostrare che i cervelli lavorano diversamente, che pensiamo diversamente? ( Alan Turing)
                  Sempre il mare, uomo libero, amerai!
                  ( Charles Baudelaire )
                  #23927 Score: 0 | Risposta

                  PMC77
                  Partecipante
                    18 pts

                    Grazie mille Albratros!

                    Sostituendo alla costante il suo valore tutto fila liscio!

                    Grazie ancora!

                  Login Registrati
                  Stai vedendo 8 articoli - dal 1 a 8 (di 8 totali)
                  Rispondi a: Errore in salvataggio file in pdf (via macro)
                  Gli allegati sono permessi solo ad utenti REGISTRATI
                  Le tue informazioni: