PDA

View Full Version : PDF creating and past copy different folder



cabete
02-14-2020, 12:57 AM
Hello every one. I have a excel sheet that have some macros in.
What i want to do its when i click in a button print, create a pdf that its copy and past in two different folders.
and that its my problem, create on pdf easy, past in the same folder that excel is, easy.
But past in different folder i am try and try but not successful, and past in two different folders heaven harder.

Anyone can help me ?


Sub PDF()


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 FSO As Object
Dim FromPath2 As String
Dim ToPath2 As String
Dim ToPath3 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("D1").Value _
& " Nš" & wsA.Range("H3").Value _
& " - " & wsA.Range("H4").Value


'create default name for saving 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



FromPath2 = "G:\My disk\Buy\" & strPathFile 'Souce Folder
ToPath2 = "\\Shared_Drive\PEP\NC" 'Destination folder
ToPath3 = "\\Shared_Drive\Buy\PEP\NC" 'Destination folder


FSO.CopyFolder Source:=FromPath2, Destination:=ToPath2 and Destination:=ToPath3
MsgBox "Ficheiros Foram Copiados "



'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


End Sub