Página 1 de 1

Exportar para PDF com VBA

Enviado: 26 Mar 2020 às 22:31
por fernandoreus
Estou precisando de um código VBA, e não consegui encontrar no fórum e nem na internet, que seria exportar a planilha 8 do arquivo que estou enviando como exemplo, e alem de exportar para .pdf, quero que nomeie o arquivo novo, como "Arquivo-" e depois "CélulaA1[que é o nome da pessoa" e depois "data".

Ficando como Exemplo: Arquivo - Fernando26032020.pdf

Tenho o Office 2019, e rodo ele no Mac

Re: Exportar para PDF com VBA

Enviado: 27 Mar 2020 às 07:38
por JCabral
Tente adaptar esse código ao seu caso:
Código: Selecionar todos
Sub PDFActiveSheetNoPrompt()
'www.contextures.com
'for Excel 2010 and later
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
On Error GoTo errHandler

Set wbA = ActiveWorkbook
Set wsA = ActiveSheet

'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
  strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"

strName = wsA.Range("A1").Value _
          & " - " & wsA.Range("A2").Value _
          & " - " & wsA.Range("A3").Value

'create default name for savng file
strFile = strName & ".pdf"
strPathFile = strPath & strFile

'export to PDF in current folder
    wsA.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=strPathFile, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=False
    'confirmation message with file info
    MsgBox "PDF file has been created: " _
      & vbCrLf _
      & strPathFile

exitHandler:
    Exit Sub
errHandler:
    MsgBox "Could not create PDF file"
    Resume exitHandler
End Sub

Re: Exportar para PDF com VBA

Enviado: 27 Mar 2020 às 12:20
por fernandoreus
Então fiz isso, vou colocar o código, porém quando eu mudo o arquivo .xlsm de pasta, ele não está mais salvando em .pdf ele busca minha impressora, mas não consegui identificar o erro. Conseguiria me ajudar?
Código: Selecionar todos
Sub Imagem2_Clique()
Dim LocalPDF As String
LocalPDF = ThisWorkbook.Path & "/" & "Orçamento - " & Sheets("Dados Cliente").Range("D2").Value & " - " & Replace(Date, "/", "-")
    Sheets("Impressão").ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
        LocalPDF & ".pdf", Quality:= _
        xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        OpenAfterPublish:=False
    Sheets("Dados Cliente").Select
End Sub

Exportar para PDF com VBA

Enviado: 28 Mar 2020 às 14:20
por JCabral
Coloque um exemplo, tirando dados sensíveis, mas com todo o formato igual ao original