VBA object property change not recognized


C

caten

I am trying to use a custom user form to access, edit, and save the
AlternativeText property of an image or object (usually a group of images). I
think I have VBA that does what I want, but in testing it, I'm seeing some
odd PowerPoint (2002 SP3) behavior that is defeating my VBA.

Here's what I have:

*****************
Option Explicit
Public strAltText 'Has to be public to persist in user form
-----------------
Sub SetAltText()
Dim oShape As Shape

'Display the current alternate text
Call GetAltText

Debug.Print "4. Text returned by GetAltText: " & strAltText
Set oShape = ActiveWindow.Selection.ShapeRange(1)
oShape.AlternativeText = strAltText
Debug.Print "5. Shape's alt text: " & oShape.AlternativeText

'ExitNow:
End Sub
-----------------
Sub GetAltText()

Dim oShape As Shape

Set oShape = ActiveWindow.Selection.ShapeRange(1)
strAltText = oShape.AlternativeText

With frm_altText
'Initialize form control with current alternate text
.txt_alt_text.Text = strAltText

Debug.Print "1. Alt text to initialize form: " & strAltText 'Prints the
OLD text

'Prompt to set or edit alt text
.Show

'Update alternate text with text from form control
'If Cancel was clicked, then strAltText wasn't recaptured from the form
control anyway
Debug.Print "2. Alt text received from form: " & strAltText 'Prints the
NEW text
oShape.AlternativeText = strAltText
Debug.Print "3. Shape's alt text after form use: " &
oShape.AlternativeText 'Prints the NEW text

'This works, but I don't want to run it every time I set alt text:
'CommandBars.FindControl(Id:=30006).Execute 'Click the Format menu
'CommandBars.FindControl(Id:=2624).Execute 'Click Picture/Object on the
Format menu
'SendKeys "{ENTER}"

End With
-----------------
The User Form contains (1) a text input box named txt_alt_text, (2) an OK
button, and (3) a Cancel button.

(1) The text input box has no VBA associated with it.

(2) OK BUTTON:
Private Sub btn_ok_alt_text_Click()
'Save data
With frm_altText
strAltText = .txt_alt_text.Text
End With
Unload frm_altText
End Sub

(3) Cancel BUTTON:
Private Sub btn_cancel_alt_text_Click()
Unload frm_altText
End Sub
-----------------
Output to Immediate window:
1. Alt text to initialize form:
2. Alt text received from form: NEW ALT TEXT
3. Shape's alt text after form use: NEW ALT TEXT
4. Text returned by GetAltText: NEW ALT TEXT
5. Shape's alt text: NEW ALT TEXT

*****************

Now for the odd behavior. When I click my Set Alt Text button and revise an
object's alt text, my revisions seem to be captured by the user form and
returned correctly. If I click my Set Alt Text button again, I can see my
revised text. But, if I close the PPT file, it closes without recognizing my
revisions and prompting me to save changes. And if I manually save the file
before closeing it, my revisions are lost (gone when I re-open the file).
Oddly, if I open the Format Picture (or Format Object) dialog box (at any
time, before or after using my Set Alt Text button to edit an object's alt
text), DO NOTHING (not even click the Web tab to actually SEE the alt text),
and THEN close the PPT file, PowerPoint recognizes and prompts me to save my
revisions. (I've tried many variations of this test, but this one illustrates
the crux of the problem, I think.)

It seems that the only way PowerPoint "knows" that I have changed the
AlternativeText property of an object, is if the Format Picture (or Format
Object) dialog box was opened. (In fact, if I open a file, DO NOTHING, open
the Format dialog box, DO NOTHING, and then close the file, PowerPoint
recognizes and prompts me to save my revisions -- even though I didn't make
any revisions.)

Is there a way in VBA, to simulate opening the Format dialog box, or
otherwise "force" PowerPoint to recognize that the AlternativeText property
of an object has changed? Maybe there's an event that causes PowerPoint to
try to determine whether changes have occurred so that it can prompt me to
save my changes before closing?

Any other ideas?
 
Ad

Advertisements

S

Shyam Pillai

Hi,
I can repro the said odd behavior. The simple solution would be to flag the
presentation as dirty so that it will prompt to save when closing the
presentation.
This can be done by running the following command after you change the
AlternateText property:

Activepresentation.Saved = False

Regards,
Shyam Pillai

Animation Carbon: http://www.animationcarbon.com
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top