0

There has been a question similar to this on How to Convert Excel Cell Values Into Individual PNG Files, however (#1) I haven't been able to overcome the "Run-Time 70: Permission Denied Error" and (#2) I want to name each individual PNG file as a corresponding number on the Excel sheet. For example, I have an Excel document that contains in Column A a list of numbers and in Column B a list of cities. I want to get a PNG file of the word that has the city name in Column B, and I want that PNG file to be named the corresponding number in Column A.

For Example:

Column A Column B
1 Tokyo
2 New York

1.png = Image of the cell word Tokyo

2.png = Image of the cell word New York

I've tried hours and hours on this and I can't seem to get over the "Run-Time 70: Permission Denied Error". Also, I found this example of a code that I thought I was so close to getting to work, but it only worked for .txt format and not .png format. Here is the code for that:

Sub Create_Txt_File()
  Dim a As Variant, i As Long
  
  a = Range("C1:G" & Range("G" & Rows.Count).End(3).Row).Value2
  For i = 1 To UBound(a, 1)
    Open "/Users/mycomputer/Desktop" & "/" & a(i, 1) & ".txt" For Output As #1
    Print #1, a(i, 5)
    Close #1
  Next i
End Sub

Like I said, this was ALMOST perfect for what I needed done, however, I tried to change the variables to .png but was never able to get the files to open properly. I assume it must be more complicated than simply changing ".txt" to ".png" in the code. If anyone could help me out with this, it would be amazing! I'm trying to turn around 20,000 Excel Cells into individual PNG files, and I definitely do not want to have to manually enter all of the information if I can help it.

  • PNG is a lot more complicated than “writing pixels to a file”, it is a compressed image file with a complex algorithm. You better find a library that does what you want, or maybe save the image in BMP format. – eventHandler Sep 06 '22 at 02:53
  • Typical way to do this is to paste a picture of the range into a chart then use the chart's Export method - eg https://www.mrexcel.com/board/threads/vba-to-save-range-as-png-or-jpeg.1139047/ – Tim Williams Sep 06 '22 at 04:33
  • 2
    or https://stackoverflow.com/questions/42091390/vba-range-to-jpg-picture/42092375#42092375 – Tim Williams Sep 06 '22 at 05:20
  • Once you've found a suitable way to create your file, you might also want to revisit the code you've provided above. Your example has the filename in Column A, yet your code above is using column C to supply the filename - which is possibly the cause of your error 70. – CLR Sep 06 '22 at 06:43

0 Answers0