0

I have a macro that takes a range of cells, copies them as an image, and places them in a separate sheet. I would like to take the image, resize it, and place the correctly sized image into a different sheet.

Sub heatmapToJPEG()

Range("G1:V33").Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture

'places image of heat map into Setup tab
Sheets("Setup").Select
Range("M1").Select
ActiveSheet.Paste

End Sub

I would like to re-size the image one it is in the Setup tab, but when excel places it there, it gives it the default name of Picture 1, Picture 2, Picture 3, or whatever iteration I am on before closing and reopening the workbook.

Is there a way to assign a permanent variable name to the image found in the Setup tab? If so, my thinking was to assign it to the variable name, and pass it off to another sub for resizing and placement. I am sure there are better ways, but am hitting this roadblock.

Rivers31334
  • 644
  • 1
  • 12
  • 30

1 Answers1

0

It's bad practice all around but just add a .Name property at the end -

ActiveSheet.Paste
Selection.Name = "name"
Raystafarian
  • 2,902
  • 2
  • 29
  • 42
  • What would be a more elegant or better practiced method? Still learning. – Rivers31334 Feb 23 '16 at 18:52
  • To not use any `.Select` or `.ActiveSheet` or `.Paste` http://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros - I don't know a more elegant way to give it a name though. – Raystafarian Feb 23 '16 at 19:12