Página 1 de 1

Exportar de Excel para PDF, com destino específico

Enviado: 24 Set 2020 às 09:43
por Rutra
Olá! Preciso da vossa ajuda.
Criei um aplicativo Excel, com várias folhas interligadas. Apliquei um comando VBA, cujo código procurei na net, com o intuito de exportar a Folha4 em formato PDF. No entanto, a exportação ocorre sempre para o Desktop, e eu precisava que a exportação fosse feita para uma pasta específica ("Totais"), na partição T:\ do servidor.
Onde se acrescenta, no código, essa indicação?
Obrigado!

Sub PDFActiveSheet()
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
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 = Folha4
strTime = Format(Now(), "yyyymmdd\_hhmm")

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

'replace spaces and periods in sheet name
strName = Replace(wsA.Name, " ", "")
strName = Replace(strName, ".", "_")

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

'use can enter name and
' select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strPathFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")

'export to PDF if a folder was selected
If myFile <> "False" Then
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
'confirmation message with file info
MsgBox "Foi criado ficheiro PDF: " _
& vbCrLf _
& myFile
End If

exitHandler:
Exit Sub
errHandler:
MsgBox "Não foi criado o ficheiro PDF"
Resume exitHandler
End Sub

Re: Exportar de Excel para PDF, com destino específico

Enviado: 24 Set 2020 às 14:04
por babdallas
Este código pergunta ao usuário qual o caminho onde será salvo. Basta você escolher o servidor T: e a pasta desejada.

Re: Exportar de Excel para PDF, com destino específico

Enviado: 24 Set 2020 às 14:18
por osvaldomp
substitua
Código: Selecionar todos
strPath = wbA.Path
por
Código: Selecionar todos
strPath = "T:\Totais"