I have a sheet in which I refresh a picture in a particular cell (F13 in this instance) based on a text string which is converted into a picture via an add-in.
The sheet also contains a validation pulldown list, and several other images and shapes (as macro buttons).
Each time I want to refresh the picture with a different one, I delete the 1st picture, copy the new text string (from cell Q20) and paste into cell F13, and then re-iterate the process. This is done via a macro called "template" in Excel 2003.
Initially, I used the following code for the "delete-copy-paste" sequence:
This works, but I wanted to improve the code by avoiding "select' statements, and the "processdeletekeystroke" code.
My initial thought was to use the following (which again works, BUT I later found out that
it quite happily deleted my validation list too!) in order to remove the picture as a shape:
With this in mind, I then used the following code, which works nicely (or so I thought):
The problem with this is that it only works if the validation pull down list is left empty; if I select an item from the list, and then try and delete the picture, i get the following error:
Run-time error '1004': Application-defined or object-defined error.
I should note that the following code does NOT work in Excel 2003 (works in 2007, but suffers from the same validation list error):
So my final complete code (macro "template") for the entire process is as follows:
I have several questions (or should I say frustrating difficulties) with this code. I list them in order of importance!
1. Why does the picobj.delete code error when the validation list is populated? How can I delete ONLY the picture of interest?
2. There is one major flaw that is hampering my overall spreadsheet, and I am convinced it is related to the add-in. Often, the sheet will appear to get stuck in some loop, whereby the page will 'pulse' and the only way to disrupt it is by holding down "ESC". I managed to catch it with the macro recorder, and all I got was hundreds of "Application.run range()" streaming down the page. You would make my day if you could offer some insight into this.
3. The re-pagination sequence does not always work, in that the column widths and row heights are not always enforced first time around after the new picture is generated.
If I place the re-pagination sequence using a "Worksheet_Activate" sub in the worksheet module and then re-activate the sheet (either manually or via a macro), the pagination becomes enforced. Any reason why this should be? I can live with this, but it would be nice to have it all happen in the one macro sequence
Bookmarks