Я хочу сделать PDF из моего листа в динамической папке, это означает, что имя этой папки зависит от значения некоторых ячеек, сначала я создал его ранее, затем мне нужно преобразовать свой лист в PDF в эту папку,
ниже вы можете увидеть мой путь:
папка dynamaic -----> спецификация ----------> pdf
Я написал некоторый код, но ничего не произошло. Я надеюсь, что какое-то тело поможет мне,
Sub creatpdf()
Dim lLastRow As Long
Dim sPath As String, sNewFolder As String
Dim x As String
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
With Worksheets("Output_" & Date)
fName5 = .Range("D3").Value
fName3 = "PO_"
fName1 = "000"
fName2 = .Range("B3").Value
fName4 = "_"
End With
BrowseForFolder = CurDir()
sPath = BrowseForFolder & "\" & fName3 & fName5 & "\"
lLastRow=Workbooks(sFilename).Sheets(1).Range("A:A").SpecialCells(xlCellTypeLastCell).Row
Workbooks(sFilename).Sheets(1).Activate
For i = 2 To lLastRow
If Workbooks(sFilename).Sheets(1).Cells(i, 5).Value >= 1 Then
sNewFolder = "000" & ActiveSheet.Range("B" & i).Value & "_" & ActiveSheet.Range("D" & i).Value & "_" & ActiveSheet.Range("I" & i).Value & "_" & Format$(Date, "yyyymmdd") & "\" & BOM
If Dir(sPath & "\" & sNewFolder, vbDirectory) = "" Then
With ActiveSheet.PageSetup
End With
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath =sPath & "\" & sNewFolder
strName = Folder_BOM & "\" & fName5 & fName6
'create default name for savng file
strFile = strName & ".pdf"
strPathFile = strFile
'export to PDF in current folder
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPathFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
MsgBox "PDF file has been created: " _
& vbCrLf _
& strPathFile
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End If
End If
sNewFolder = vbNullString
Next
End Sub