View Full Version : Export And Save Chart As PNG With Custom Sequential Name
CORAL
03-03-2014, 08:09 PM
I want to have png file name as d140302.png the next one d140303.png instead of Chart 49 02-03-14_03.42.51_PM.PNG please help me i attached the png file1501
Sub blah()
With ThisWorkbook.Worksheets("min max & march of khamir")
For i = 1 To 61 Step 2
lr = .Cells(Rows.Count, i + 1).End(xlUp).Row
.ChartObjects("Chart 2").Chart.SetSourceData Source:=.Range(.Cells(1, i), .Cells(lr, i + 1))
.ChartObjects("Chart 2").Chart.Export ThisWorkbook.Path & Application.PathSeparator & "Chart " & Format(i, "00") & " " & Format(Now, "DD-MM-YY_HH.MM.SS_AM/PM") & ".PNG"
Next i
End With
End Sub
Excel Fox
03-03-2014, 09:54 PM
Use this
Format(now(),"""d""yymmdd"".PNG""")
p45cal
03-03-2014, 10:26 PM
This is really a continuation of this thread: http://www.excelfox.com/forum/f2/insert-line-graph-for-each-column-separatly-with-vbulletin-1712/
where the dates to be used are on the sheet.
Change the export line to:
.ChartObjects("Chart 2").Chart.Export ThisWorkbook.Path & Application.PathSeparator & "d" & Format(.Cells(1, i + 1).Value, "yymmdd") & ".PNG"
CORAL
03-04-2014, 08:19 AM
when i run this code in to this worksheet i face with this error .ChartObjects("Chart 2").Chart.SetSourceData Source:=.Range(.Cells(1, i), .Cells(lr, i + 1)) highlighted
Sub blah()
With ThisWorkbook.Worksheets("min max & march of khamir")
For i = 1 To 61 Step 2
lr = .Cells(Rows.Count, i + 1).End(xlUp).Row
.ChartObjects("Chart 2").Chart.SetSourceData Source:=.Range(.Cells(1, i), .Cells(lr, i + 1))
.ChartObjects("Chart 2").Chart.Export ThisWorkbook.Path & Application.PathSeparator & "d" & Format(.Cells(1, i + 1).Value, "yymmdd") & ".PNG"
Next i
End With
End Sub
Admin
03-04-2014, 08:29 AM
@ MARJAN_MASHAYEKHPOOR
Please do not start a new thread. Stick with your original thread. Also please add code tags while posting codes.
Admin
03-04-2014, 08:35 AM
Couple of things.
1. Your chart name is "Chart 9"
2. Your chart is in sheet "Sheet3"
try this
Sub blah()
Dim chtChart As Chart
Dim i As Long
Dim lRow As Long
Set chtChart = ThisWorkbook.Worksheets("Sheet3").ChartObjects("Chart 9").Chart
With ThisWorkbook.Worksheets("min max & march of khamir")
For i = 1 To 61 Step 2
lRow = .Cells(Rows.Count, i + 1).End(xlUp).Row
chtChart.SetSourceData Source:=.Range(.Cells(1, i), .Cells(lRow, i + 1))
chtChart.Export ThisWorkbook.Path & Application.PathSeparator & "d" & Format(.Cells(1, i + 1).Value, "yymmdd") & ".PNG"
Next i
End With
End Sub
CORAL
03-04-2014, 01:07 PM
i think it is the last question about this thread...
the title of column changed to text format cell as i send but i have to save my png as before so what should i do with this code and this excel file to have png export file as before (d140301.png)
(i attached an image)
Sub blah()
Dim chtChart As Chart
Dim i As Long
Dim lRow As Long
Set chtChart = ThisWorkbook.Worksheets("Sheet3").ChartObjects("Chart 9").Chart
With ThisWorkbook.Worksheets("min max & march of khamir")
For i = 1 To 61 Step 2
lRow = .Cells(Rows.Count, i + 1).End(xlUp).Row
chtChart.SetSourceData Source:=.Range(.Cells(1, i), .Cells(lRow, i + 1))
chtChart.Export ThisWorkbook.Path & Application.PathSeparator & "d" & Format(.Cells(1, i + 1).Value, "yymmdd") & ".PNG"
Next i
End With
Excel Fox
03-04-2014, 07:32 PM
Coral, you aren't adding code tags to your codes. Code tags add readability. Instruction is clearly given above the editor. Please ensure you follow this. Also, your last question is not clear. Can you please clarify.
CORAL
03-05-2014, 09:29 PM
1503every thing is ok until i must change the title of column 01-mar-14 (format cell= date) in to 01-mar-2014 khamir (text format) so the export png file name is not as before and change from d140301.png in to d01-mar-2014 khamir.png
so what should i do and how edit this line of code to have file names as d140301.png [PHP][Application.PathSeparator & "d" & Format(.Cells(1, i + 1).Value, "yymmdd") & ".PNG"
Next i
End With/PHP] the excel example is attached as image
CORAL
03-07-2014, 04:45 PM
1506every thing is ok until i must change the title of column 01-mar-14 (format cell= date) in to 01-mar-2014 khamir (text format) so the export png file name is not as before and change from d140301.png in to d01-mar-2014 khamir.png
so what should i do and how edit this line of code to have file names as d140301.png
Application.PathSeparator & "d" & Format(.Cells(1, i + 1).Value, "yymmdd") & ".PNG"
Next i
End With the excel example is attached as image
p45cal
03-07-2014, 10:21 PM
as long as the date in the cell has no spaces at the beginning then this should work:
chtChart.Export ThisWorkbook.Path & Application.PathSeparator & "d" & Format(CDate(Split(.Cells(1, i + 1).Value)(0)), "yymmdd") & ".PNG"
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.