Hence the failure when it tries doing something to the picture which isn't really pasted yet.Īn indication of this problem is that the code runs without error when stepping through in the VB Editor with the F8 key, but fails at full speed when running with the F5 key. Like Max, I have found that many commands in Excel that operate on various objects (shapes, charts, pictures, worksheets, workbooks, etc.) take longer than they used to, and VBA doesn't wait for them to finish before trying to execute the next command. With Sheets(sheetName).chartobjects.Add( _ Try the edit below Sub createPNG(sheetName As String, rangeName As String, fileName As String) you should add some control to this to stop it looping on paste errors! paste just doesn't seem to work the first time around especially if the item is already in the clipboard! I've added a few lines to check if there is an picture present before trying to select the picture! if it's not found then it will attempt the. Width:=rSelection.Width 2, Height:=rSelection.Height 2) Left:=rSelection.Left, Top:=rSelection.Top, _ With Sheets(sheetName).ChartObjects.Add( _ '-Create an empty chart, slightly larger than exact size of range copied RSelection.CopyPicture Appearance:=xlScreen, Format:=xlPicture '- copy selected range as picture (not as bitmap) VFilePath = "Z:\marginsOutput\Charts\"
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |