Hello,
I get above mentioned error code when I try to run the following macro:
Someone gave me this code, but it does not work.
It is an excelmap containing app 70 different worksheets.
On each worksheet there is in cell I1 the path to a server address (IP/path) and in cell I2 the file name, which contains "year name.02.01 - name"
Each sheet has the be stored as pdf under the mentioned path (I1) with the mentioned name (I2)
If the path does not exist the macro should create this path and store the file as descibed.
The red marked section turns to yellow when I open the debug mode.
Can anyone pls help?
I get above mentioned error code when I try to run the following macro:
Rich (BB code):
Sub PrintAndSavePdf()
Dim strFileName As String
Dim strPath As String
Dim ws As Worksheet
Dim strPathSplit As Variant
Dim myTempPath As String
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Master" Then
strFileName = ws.Range("I2") & ".pdf"
strPath = ws.Range("I1")
myTempPath = ""
If Dir(strPath, vbDirectory) = "" Then
strPathSplit = Split(strPath, "\\")
If UBound(strPathSplit) > 0 Then
myTempPath = "\\"
strPathSplit = Split(strPathSplit(1), "\")
End If
myTempPath = myTempPath & strPathSplit(0) & "\"
For i = 1 To UBound(strPathSplit)
myTempPath = myTempPath & strPathSplit(i) & "\"
If Dir(myTempPath, vbDirectory) = "" Then
MkDir (myTempPath)
End If
Next i
End If
ws.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=strPath & strFileName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
Next ws
End Sub
Someone gave me this code, but it does not work.
It is an excelmap containing app 70 different worksheets.
On each worksheet there is in cell I1 the path to a server address (IP/path) and in cell I2 the file name, which contains "year name.02.01 - name"
Each sheet has the be stored as pdf under the mentioned path (I1) with the mentioned name (I2)
If the path does not exist the macro should create this path and store the file as descibed.
The red marked section turns to yellow when I open the debug mode.
Can anyone pls help?
Last edited by a moderator: