Excel Print to PDF Macro Run-time error '-2147024773 (8007007b) Document not saved

mazher

Active Member
Joined
Nov 26, 2003
Messages
310
Hi VBA Gurus I am using the following code and getting the error -2147024773 (8007007b) Document not saved

VBA Code:
Sub Print_PDF()
    Dim ThisFile As String
    Dim ThisPath As String
    
    With Worksheets("Autoclinics")
    
        With .PageSetup
            .RightFooter = "Printed on &D at  &T"
            .PrintQuality = 600
            .CenterHorizontally = True
            .CenterVertically = False
            .Orientation = xlLandscape
            .Draft = False
            .PaperSize = xlPaperA4
        End With
    
          
            
            ThisFile = .Range("AA2").Value
            ThisPath = .Range("AB2").Value
            
        
            .Range("D3:R40").ExportAsFixedFormat _
                   Type:=xlTypePDF, _
                   Filename:=ThisPath & ThisFile & ".pdf", _
                   Quality:=xlQualityStandard, _
                   IncludeDocProperties:=True, _
                   IgnorePrintAreas:=False, _
                   OpenAfterPublish:=False
        
        
        Application.StatusBar = False
        
    End With
    
      
End Sub

Please can someone help me.

Once its sorted i need to print another range T3:Z21 and convert it to PDF and add in the above code. the above code is for page 1 and range T3:Z21 is for page 2 in the same .pdf file.

Value in AA2 = F:\FOLDER\CS\TEST\ (this is s text value)
Value in AB2 = 12102020 (this is a number ) basically i want today's date here)

I will be extremely thankful if anyone can help me.
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,977
Office Version
  1. 365
Platform
  1. Windows
Debug.Print wrires to VBA immdiate window and can help diagnose problems

Below ...
VBA Code:
ThisPath = .Range("AB2").Value
Insert ...
VBA Code:
Debug.Print ThisPath & ThisFile & ".pdf"
Exit Sub

Run the macro again
Next ... Look in VBA immediate window ( display from menu View \ Immediate Window )

Does the path exist?
Is "\" included after path and before file name?
etc
 

mazher

Active Member
Joined
Nov 26, 2003
Messages
310
Thanks Yongle, It worked and i found the problem
VBA Code:
            ThisFile = .Range("AB2").Value
            ThisPath = .Range("AA2").Value

I have swapped the variables, my mistake

Please can you help me adding the second page for the range T3:Z21 in the same PDF.

I will be extremely thankful to you for your time and help
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,977
Office Version
  1. 365
Platform
  1. Windows
Glad it fixed your problem
New question unrelated to thread title requires a new thread
 

Watch MrExcel Video

Forum statistics

Threads
1,126,983
Messages
5,621,966
Members
415,869
Latest member
LWSkinner

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
Top