0

I managed to implement code that exports as JPG using charts. However, when I try to change the file export path, the Error I get is Run-time error 1004: Method "Range object"_Global failed I don't understand what the code is not reading as paths are similar.

If anyone can help, I'd appreciate it.

The jpg exports to *Path = ThisWorkbook.Path *Path = ThisWorkbook.Path & "\" & Range("PDF_Folder").Value

Does not export to *Path = ThisWorkbook.Path & "\" & Range("New_Folder").Value

'//Creat a jpg image using charts
 Dim rng As Range
 Dim shtTemp As Worksheet
 Dim chtTemp As Chart
 Application.ScreenUpdating = False
 '// Range
 Set rng = Worksheets("Receipt").Range("B2:E27")
 shReceipt.rows("2:27").EntireRow.AutoFit
 '// Add a temp worksheet. Chart will be placed on this. It will be deleted after
 Set shtTemp = Worksheets.Add
 '// Add chart
 Charts.Add
 '// Move the chart to the new sheet and get a reference to it
 ActiveChart.Location Where:=xlLocationAsObject, Name:=shtTemp.Name
 Set chtTemp = ActiveChart
 '// Copy and paste the range
 rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture
 chtTemp.Paste

 With ActiveChart.Parent
.Height = 520 ' resize
.Width = 360 ' resize
 End With


 '// Export

ChDir ActiveWorkbook.Path
Dim Name As String, Path, filename
Name = InvTable.ListColumns("Customer").DataBodyRange(r).Value
Dim Inv As Double
Inv = InvTable.ListColumns("Invoice Number").DataBodyRange(r).Value

filename = "\" & Inv & "_" & Name & ".jpg"
''//This PDF folder is recognised-no error
Path = ThisWorkbook.Path & "\" & Range("PDF_Folder").Value

''//This path is regonised-no error
'Path = ThisWorkbook.Path

''//This New folder creates an error (it does exist in the workbook path
''Path = ThisWorkbook.Path & "\" & Range("New_Folder").Value
chtTemp.Export filename:=Path & filename
braX
  • 11,506
  • 5
  • 20
  • 33

1 Answers1

0

So I got to the answer. "Excel_Folder" is a named range in cell (1,1) "PDF_Folder" is a named range in cell(1,2) The scope of these ranges are the Workbook

I defined "New_Folder" as a named range and the path was found.