0

I would need to write a VBA macro that automatically saves a range of cells in Excel as an image file (snapshot). Is there any easy way to do this? As my use case requires doing this many times in many sheets, the manual procedure is not suitable and I need a macro instead.

What is commented in Excel Macro - Take a snapshot of Particular Range seems pretty close to what I need, but I need to save the resulting image in a .png or .docx file rathern than pasting it in an Excel sheet.

Any idea would be great.

user173026
  • 11
  • 3
  • See linked post for saving to an image file. To save in a docx you can use the `Range.CopyPicture` method and paste into a Word doc. – Tim Williams May 08 '22 at 19:25
  • Thanks a lot! That's very useful! It is working, but I have a minor issue with the Word doc. I use this to open an existing file: `Set wd = objWordApp.Documents.Open(fileString)`. Is there any variant that I can use in order to create the file if it does not exist and to rewrite it all if it already exists? – user173026 May 09 '22 at 10:11
  • You can use `Dir(fileString)` to check if the file exists before trying to open it. If if doesn't exist you can use `Set wd = objWordApp.Documents.Add()` and `wd.SaveAs` to create it. – Tim Williams May 09 '22 at 15:43

0 Answers0