Fórum Excel Bácico, Avançado e Vba
Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.
Fórum Excel Bácico, Avançado e Vba

Este fórum é destina a usuário de Excel, que queiram compartilhar informações a básicas, avançadas e programação em VBA...
 
InícioInício  Últimas imagensÚltimas imagens  ProcurarProcurar  RegistarRegistar  Entrar  

 

 Salvar planilha em PDF, através de botão

Ir para baixo 
2 participantes
AutorMensagem
jrsetti




Mensagens : 2
Data de inscrição : 18/08/2011

Salvar planilha em PDF, através de botão Empty
MensagemAssunto: Salvar planilha em PDF, através de botão   Salvar planilha em PDF, através de botão EmptyQui Ago 18, 2011 10:55 am

Ola pessoal,

Sou novo por aki e no VBA, então se puderem me ajudar:

Tenho uma planilha e nela há um botão, quando clico nesse botão preciso que a planilha seja salva no formato PDF em um determinado lugar,
tentei com o seguinte codigo, ele até gera o arquivo, mas quando vou abri-lo apresenta um erro no adobe reader informando que não pode abrir o arquivo.

ActiveWorkbook.SaveAs "C:\teste.pdf", FileFormat:=???

??? não sei oque por, ja tentei varios

se puderem me ajudar, eu agradeço
Ir para o topo Ir para baixo
alexandrevba

alexandrevba


Mensagens : 1820
Data de inscrição : 13/07/2011
Localização : Serra - ES

Salvar planilha em PDF, através de botão Empty
MensagemAssunto: Re: Salvar planilha em PDF, através de botão   Salvar planilha em PDF, através de botão EmptySex Ago 19, 2011 2:48 am

Boa noite!!

Ai vai...

Option Explicit

Sub PrintToPDF_Early()
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from http://sourceforge.net/projects/pdfcreator/)
' Designed for early bind, set reference to PDFCreator

Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim bRestart As Boolean

'/// Change the output file name here! ///
sPDFName = "testPDF.pdf"
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator

'Check if worksheet is empty and exit if so
If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub

'Activate error handling and turn off screen updates
On Error GoTo EarlyExit
Application.ScreenUpdating = False

Set pdfjob = New PDFCreator.clsPDFCreator

'Check if PDFCreator is already running and attempt to kill the process if so
Do
bRestart = False
Set pdfjob = New PDFCreator.clsPDFCreator
If pdfjob.cStart("/NoProcessingAtStartup") = False Then
'PDF Creator is already running. Kill the existing process
Shell "taskkill /f /im PDFCreator.exe", vbHide
DoEvents
Set pdfjob = Nothing
bRestart = True
End If
Loop Until bRestart = False

'Assign settings for PDF job
With pdfjob
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With

'Delete the PDF if it already exists
If Dir(sPDFPath & sPDFName) = sPDFName Then Kill (sPDFPath & sPDFName)

'Print the document to PDF
ActiveSheet.PrintOut copies:=1, ActivePrinter:="PDFCreator"

'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False

'Wait until the file shows up before closing PDF Creator
Do
DoEvents
Loop Until Dir(sPDFPath & sPDFName) = sPDFName

Cleanup:
'Release objects and terminate PDFCreator
Set pdfjob = Nothing
Shell "taskkill /f /im PDFCreator.exe", vbHide
On Error GoTo 0
Application.ScreenUpdating = True
Exit Sub

EarlyExit:
'Inform user of error, and go to cleanup section
MsgBox "There was an error encountered. PDFCreator has" & vbCrLf & _
"has been terminated. Please try again.", _
vbCritical + vbOKOnly, "Error"
Resume Cleanup
End Sub



Att..
Ir para o topo Ir para baixo
jrsetti




Mensagens : 2
Data de inscrição : 18/08/2011

Salvar planilha em PDF, através de botão Empty
MensagemAssunto: Re: Salvar planilha em PDF, através de botão   Salvar planilha em PDF, através de botão EmptySex Ago 19, 2011 6:48 am

Alexandre,

Deu um erro na linha:

Dim pdfjob As PDFCreator.clsPDFCreator

parece que não encontra esse tipo de veiravel.

obs: tenho pdf creator instalado
Ir para o topo Ir para baixo
Conteúdo patrocinado





Salvar planilha em PDF, através de botão Empty
MensagemAssunto: Re: Salvar planilha em PDF, através de botão   Salvar planilha em PDF, através de botão Empty

Ir para o topo Ir para baixo
 
Salvar planilha em PDF, através de botão
Ir para o topo 
Página 1 de 1
 Tópicos semelhantes
-
» Salvar planilha em PDF ou Jpeg
» PLANILHA COMPARTILHADA OCORRE ERRO AO TENTAR SALVAR
» como salvar a planilha ativa em pdf e anexar o pdf no email que esta na celula B7
» Abrir planilha com um form fixo e os comandos que esta na planilha funcionarem.
» Macro para copiar dados de uma planilha e colar na última linha vazia de outra planilha

Permissões neste sub-fórumNão podes responder a tópicos
Fórum Excel Bácico, Avançado e Vba :: Intermediário :: Excel Intermediário-
Ir para: