Salvataggio file excel come PDF tramite pulsante

Anonimo
2012-10-23T09:56:31+00:00

Salve a tutti!

Avrei gentilmente bisogno di associare un'azione ad un pulsante creato in un foglio excel in modo tale che premendo il pulsante il sistema in automatico mi prenda tutte le celle dove c'è scritto qualcosa e me li salvi in un percorso prestabilito nella mia rete ma in formato PDF.

Il tutto magari tramite VBA

In attesa Vi ringrazio in anticipo

Massimo

Microsoft 365 e Office | Excel | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento
Risposta accettata dall'autore della domanda
Anonimo
2012-10-23T11:19:12+00:00

Sub SalvaInPDF()

    Const cPath  As String = "c:"

    Dim varNomeFile As Variant

    varNomeFile = Application.InputBox(Prompt:="Scrivi il nome del file PDF", _

        Title:="Nome dal file PDF da salvare", _

        Type:=2)

    If varNomeFile = False Then Exit Sub

    If Len(varNomeFile & vbNullString) = 0 Then Exit Sub

    ActiveSheet.ExportAsFixedFormat _

        Type:=xlTypePDF, _

        Filename:=cPath & varNomeFile, _

        Quality:=xlQualityStandard, _

        OpenAfterPublish:=False

End Sub


Devi solo decidere cosa succede se non scrivi nulla nella InputBox. Nel codice ho stabilito che la procedura esca senza fare altro. Potresti eventualmente assegnare un nome di default al file.

David

La risposta è stata utile?

2 persone hanno trovato utile questa risposta.
0 commenti Nessun commento

51 risposte aggiuntive

Ordina per: Più utili
  1. Anonimo
    2015-01-20T11:46:02+00:00

    Grazie Norman, tutto ok.

    Non mi ero accorto che, nei vari post sull'argomento, non veniva mai scritta la macro per intero :-).

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2015-01-20T11:43:03+00:00

    Ciao Gimart,

    Sostituisci il codice precedente con:

    '=========>>

    Public Sub SalvaInPDF()

        Dim varNomeFile As Variant

        Dim sPath As String, sStr As String, aStr As String, bStr As String

        Dim Res As Variant

     '  Const cPath As String = "c:"

        varNomeFile = Application.InputBox(Prompt:="Scrivi il nome del file PDF", _

                                           Title:="Nome dal file PDF da salvare", _

                                           Type:=2)

        If varNomeFile = False Or Len(varNomeFile) = 0 Then

            Exit Sub

        End If

        If Right(varNomeFile, 4) <> ".pdf" Then

            varNomeFile = varNomeFile & ".pdf"

        End If

        With Application

            sPath = .DefaultFilePath & .PathSeparator

        End With

        sStr = sPath & varNomeFile

        If Dir(sStr) = varNomeFile Then

            aStr = "Il file " & varNomeFile & " esiste gia`"

        Else

            aStr = sStr

            MsgBox Prompt:="FullName del nuovo file = " & aStr

        End If

        ActiveSheet.ExportAsFixedFormat _

                Type:=xlTypePDF, _

                Filename:=sStr, _

                Quality:=xlQualityStandard, _

                OpenAfterPublish:=False

    End Sub

    '<<=========

    ===

    Regards,

    Norman

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2015-01-20T11:25:07+00:00

    Ciao Gimart,

    Potresti, per piacere, trascrivere l'intera macro come deve essere, senza scriverla parzialmente?

    '=========>>

    Public Sub SalvaInPDF()

        Dim varNomeFile As Variant

        Dim sPath As String, sStr As String, aStr As String, bStr As String

        Dim Res As Variant

     '  Const cPath As String = "c:"

        varNomeFile = Application.InputBox(Prompt:="Scrivi il nome del file PDF", _

                                           Title:="Nome dal file PDF da salvare", _

                                           Type:=2)

        If varNomeFile = False Or Len(varNomeFile) = 0 Then

            Exit Sub

        End If

        If Right(varNomeFile, 4) <> ".pdf" Then

            varNomeFile = varNomeFile & ".pdf"

        End If

        With Application

            sPath = .DefaultFilePath & .PathSeparator

        End With

        sStr = sPath & varNomeFile

        If Dir(sStr) = varNomeFile Then

            aStr = "Il file " & varNomeFile & " esiste gia`"

        Else

            aStr = sStr

            MsgBox Prompt:="FullName del nuovo file = " & aStr

        End If

        ActiveSheet.ExportAsFixedFormat _

                Type:=xlTypePDF, _

                Filename:=cPath & varNomeFile, _

                Quality:=xlQualityStandard, _

                OpenAfterPublish:=False

    End Sub

    '<<=========

    Se incontri ancora l'errore, copia il messaggio che vedi prima del messaggio di errore in una risposta qui.

    ===

    Regards,

    Norman

    La risposta è stata utile?

    0 commenti Nessun commento
  4. Anonimo
    2015-01-20T07:12:41+00:00

    Allora la macro completa che ho scritto è questa:

    Sub SalvaInPDF()

    Const cPath  As String = "c:"

        Dim varNomeFile As Variant

    varNomeFile = Application.InputBox(Prompt:="Scrivi il nome del file PDF", _

    Title:="Nome dal file PDF da salvare", _

            Type:=2)

    If varNomeFile = False Then Exit Sub

    If Len(varNomeFile & vbNullString) = 0 Then Exit Sub

             MsgBox "Percorso = " & cPath & vbNewLine & "Nome del file = " & varNomeFile

      ActiveSheet.ExportAsFixedFormat _

    Type:=xlTypePDF, _

    Filename:=cPath & varNomeFile, _

    Quality:=xlQualityStandard, _

    OpenAfterPublish:=False

    End Sub

    Ma, quando la lancio, il messaggio è questo:

    Potresti, per piacere, trascrivere l'intera macro come deve essere, senza scriverla parzialmente?

    Grazie.

    La risposta è stata utile?

    0 commenti Nessun commento