PDA

View Full Version : [SOLVED:] Auto unformatting of output filename with leading zeroes



willspill
01-21-2020, 02:49 AM
I am trying to save a chart out of excel with a file name of the format 'run-001_plot-001.png'. The following code works correctly apart from the fact that the programme is auto deleting the leading zeroes from 'Format(j,000)' to 'Format(j,0):



ActiveSheet.ChartObjects(1).Chart.Export filename:=output_directory & "\" & "run-" & Format(j, 0) & "_" & file_name & "." & output_file_type
.Shapes(MyChart).Delete

I read something explaining that it was due to the file being written rather than read but didn't fully understand it. Any ideas?

willspill
01-21-2020, 03:04 AM
Forget I even asked, I was being stupid. The code should be 'Format(j, "000")'.