0

I have a macro that prints a chart to pdf by copying the chart to a new sheet (wstemp) and printing the new sheet. The macro works fine on my computer and my wife's, but not on the client's. He continues to get the '1004' error "paste method of range class failed". Code below, the error is on the paste line. Any thoughts would be greatly appreciated.

Sub PrintPDFLDRBD_Chart1()
'
' prints my ldr bd
'
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim ch1 As Shape
Dim pth, nme, fn, lft, chd As String
Dim wsref, wstemp As Worksheet


Set wsref = ThisWorkbook.Sheets("SheetA")
Set ch1 = wsref.Shapes("SheetAChart1")

pth = ThisWorkbook.path
fn = pth & "\" & "SheetA_ch1"

Set wstemp = Sheets.Add
ch1.Copy
wstemp.Range("A1").PasteSpecial 

With wstemp.PageSetup
     .RightHeader = Format(Now, "MMMM DD, YYYY HH:MM:SS")
     .Zoom = False
     .FitToPagesTall = 1
     .FitToPagesWide = 1
End With

  wstemp.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        fn, Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=True, OpenAfterPublish:=True
  
  wstemp.Delete

Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub
braX
  • 10,905
  • 5
  • 18
  • 32
  • I've seen this problem before and the only solution I found was to capture the error and try the paste until it succeeds - https://stackoverflow.com/a/60582628/478884 May seem a bit hacky but it does work pretty reliably. – Tim Williams Feb 26 '22 at 19:28

0 Answers0