Condividi:        

macro per creare pdf da file excel

Vuoi potenziare i tuoi documenti Word? Non sai come si fa una macro in Excel? Devi creare una presentazione in PowerPoint?
Oppure sei passato a OpenOffice e non sei sicuro di come lavorare al meglio?

Moderatori: Anthony47, Flash30005

macro per creare pdf da file excel

Postdi sprinterone » 22/10/10 09:34

Buongiorno, vi espongo un dilemma che credo possa tornare utile a molti.
Codice: Seleziona tutto
Sub crea_PDF()
'
Dim myobject As New Bullzip.PDFPrinterSettings
Dim SavePath As String, FileName As String, SheetName As String, ThisSheet As String

'Path dove salvare il pdf
Dim Unit, DirProg, DirPdf, MiaDir As String
Unit = Sheets("info").[B1]
DirProg = Sheets("info").[B2]
DirPdf = Sheets("info").[B3]
MiaDir = DirProg & DirPdf

' se non ci sono le cartelle le creo
Dim dir1 As String
    dir1 = Dir(Unit & DirProg, 16)
    If Len(dir1) = 0 Then
    ChDir Unit
    MkDir Unit & DirProg
    End If
Dim dir2 As String
    dir2 = Dir(Unit & DirProg & DirPdf, 16)
    If Len(dir2) = 0 Then
    ChDir Unit
    MkDir Unit & DirProg & DirPdf
    End If
   
'assegno un nome al file pdf
MioDoc = ActiveSheet.Name
Set NameDoc = Range("G12")
Set Nrdoc = Range("C12")
Set myDatadoc = Range("C13")

rifName = NameDoc
rifDoc = Nrdoc
Datadoc = myDatadoc
   
Dim gg, mm, aa As String
    gg = Day(myDatadoc)
    mm = Month(myDatadoc)
    aa = Year(myDatadoc)
  nomefile = MioDoc & "_" & NameDoc & " n°" & rifDoc & " del " & gg & "." & mm & "." & aa
Sheets("info").[B8] = Unit & MiaDir & nomefile & ".pdf"
Sheets("info").[B9] = Unit & DirProg
       
If LCase(Right(nomefile, 4)) <> ".pdf" Then nomefile = nomefile & ".pdf"

' setup parametri pdf
myobject.SetValue "output", Unit & MiaDir & nomefile
myobject.SetValue "showsettings", "never"
myobject.SetValue "showPDF", "yes"    ' remmare se vuoi visualizzare il PDF
myobject.WriteSettings (True)

'setto la stampante virtuale come predefinita
If InStr(ActivePrinter, "BullZip") = 0 Then
    Dim storeprinter$, PrinterChanged As Boolean
    PrinterChanged = True
    storeprinter = ActivePrinter
    ActivePrinter = GetFullNetworkPrinterName("Bullzip PDF Printer")
End If

'creo il file pdf
ActiveSheet.PrintOut

' ripristino la stampante predefinita di sistema
If PrinterChanged Then ActivePrinter = storeprinter
End Sub

Function GetFullNetworkPrinterName(strNetworkPrinterName As String) As String

Dim strCurrentPrinterName As String, strTempPrinterName As String, i As Long
strCurrentPrinterName = Application.ActivePrinter
i = 0
Do While i < 100
strTempPrinterName = strNetworkPrinterName & " su Ne" & Format(i, "00") & ":"

On Error Resume Next
Application.ActivePrinter = strTempPrinterName
On Error GoTo 0
If Application.ActivePrinter = strTempPrinterName Then
GetFullNetworkPrinterName = strTempPrinterName
i = 100
End If
i = i + 1
Loop

Application.ActivePrinter = strCurrentPrinterName
End Function

Ho provato questa macro ( non e' farina del mio sacco )che dovrebbe creare il pdf del file su cui sto lavorando, per poterlo catalogare con un nome gia' predisposto. Sembra funzionare, ma mi restituisce un pdf "bianco".
Ho provato ad associare la macro con altri progr crea-pdf (quello in oggetto e' Bullzip), ma il risultato e' identico.Chiedendo qua e la' mi e' stato risposto che potrebbe essere un conflitto con adobe, quindi l'ho disinstallato ma il problema persiste.
Qualcuno e' in grado di dirmi dove sta l'inghippo?
Giancarlo
Avatar utente
sprinterone
Utente Junior
 
Post: 51
Iscritto il: 26/01/10 10:24
Località: Monselice

Sponsor
 

Re: macro per creare pdf da file excel

Postdi Anthony47 » 23/10/10 01:48

Conosco la prestazione "ricerca su google", ma se dici direttamente dove l' hai presa possiamo verificare cosa aveva in mente il progettista.

Ciao
Avatar utente
Anthony47
Moderatore
 
Post: 19221
Iscritto il: 21/03/06 16:03
Località: Ivrea


Torna a Applicazioni Office Windows


Topic correlati a "macro per creare pdf da file excel":


Chi c’è in linea

Visitano il forum: Nessuno e 60 ospiti