Runtime Error '-2147024773 (8007007b)'

Doerte

New Member
Joined
Aug 1, 2021
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hello,
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:
Oops meant to send you this.

1628155332748.png
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi Alex,
only this is written in the immediate window:

.pdf
 
Upvote 0
1) have you proved that the create a folder part works ?
It is specific to using a network path that needs the \\ so I haven't tested it.

2) Before the line
ws.ExportAsFixedFormat Type:=xlTypePDF,
can you add this line.
VBA Code:
debug.print strPath & strFileName
It should print to the immediate window in the VBA screen.

If you can't see it press Ctrl+G when you are in the VBA window.

Copy paste the text it outputs in a reply here.
Hi Alex,
here are the answers:
1.) it worked once last year, but nothing has changed since then
2.) added the line

Immediate window just show:
.pdf
 
Upvote 0
Can you add and additional line:-

VBA Code:
debug.print ws.name, ws.Range("I2"), ws.Range("I1")
 
Upvote 0
Added the line right below Debug.Print strPath & strFileName but failure message remains the same
 
Upvote 0
It is not fixing the problem just trying to identify it.
What 2 lines did you get in the immediate window ?
Expecting previous .pdf and on the next line a sheet name and the what is I2 & I1 on the sheet (possibly blank)
 
Upvote 0
Being in Australia I will be login off shortly.
If it used to work then the sheet name in the debug.print statement is likely to point you at the source of the problem.
The only sheet being excluded by the code is the sheet called "Master".
If any other sheet (even a hidden sheet) does not have any values in I2 & I1, the code will error out.
It should produce pdf's sheets to the left of the one it errors out on. If the sheet it errors out on is the first (after master), then it will error out on the first pass.
 
Upvote 0
I discovered the path and file name of the sheet review history was in column J instead if I - it is corrected now, but the failure message remains the same
 
Upvote 0
If you have corrected it and rerun it.
The did it create a pdf for the Review History file.
What sheet name appears in the immediate box now ?
(before you run it again click in the immediate box Ctrl+A and delete, to give you a fresh screen)
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top