I routinely produce visio documents with images on each page that I paste in from another app. The files are large so need compressing, which isn't fun by hand. I want to be able to loop through each page and compress any images a set amount (75%). So far I've got a sub that selects all images on a page and I've got a sub that uses send keys to bring up the image compression window and run compression at 75%. The problem is the two won't run together. SendKeys compression works fine if I select all images first then run compression separately. But executing in the same sub doesn't work. Code I'm using below. All I can think is that something is breaking the sendkeys rhythm because instead of compressing I'll get mc 75 inserted as text below the image, which is the sendkeys keys. Or I'm stringing them together in the wrong way.
If I run the following separately they work. ie manually executing each one
'selects all images on a page
Sub SelectImagesOnPage()
Dim vsoSelection As Selection
'add all pictures to selection
Set vsoSelection = ActivePage.CreateSelection(visSelTypeByType, visSelModeSkipSuper, visTypeSelBitmap)
ActiveWindow.Selection = vsoSelection
End Sub
'uses sendkeys to bring up the compress image dialogue
Sub compressImageSelection()
'should check an image is selected.
SendKeys "%(jp)", True 'holds ALT while pressing JP
SendKeys "m", True
SendKeys "c"
SendKeys "{TAB}{TAB}"
SendKeys "75{ENTER}"
End Sub
But putting the two together like this doesn't work.
Sub compressPicturesOnPage()
'add all pictures to selection
Call SelectImagesOnPage
'compress
Call compressImageSelection
End Sub
Update: Turns out that for the context sensitive 'Compress Image' button and 'Picture Format' tab to appear on the ribbon menu all Sub's have to complete. ie. visio has to 'regain control'. Blows a hole in what I'm trying to do but at least I know now! Possible solution by Jon Fournier in the comments to try.