VBA to Applescript in PPT

P

peterthebag

Hi,
i'm trying to use some of the example code in the MS guide VBA to
applescript and I seem to be getting a lot of errors.

I am trying to get a script that allows me to format text. Based on
the guide I have been trying the code below, but keep getting errors.
Could anyone guide me as to what is wrong?

Also, the code contains VBA - which seems to defeat the point - is
there a way to do it solely in AS?

many thanks,

Peter



tell application "Microsoft PowerPoint"
--get the selected shape via the handler
set selectedShape to my GetSelectedShape() -- paste it in!
tell text range of text frame of selectedShape
tell its font
set {font name, font size, font color, bold} to ¬
{"Arial", 24, {255, 0, 0}, true}
end tell
end tell
end tell

to GetSelectedShape()
set textFilePath to (path to temporary items as string) & "Shared
Text File"
tell application "Microsoft PowerPoint"
activate
set theIndex to slide index of slide of view ¬
of active window
set selectedSlide to slide theIndex of active presentation
do Visual Basic "n =
ActiveWindow.Selection.ShapeRange.ZOrderPosition
'write n as string to text file, replacing any text there
FileNumber = FreeFile
Open \"" & textFilePath & "\" For Output As #FileNumber
Print #FileNumber, CStr(n)
Close #FileNumber
"
set n to (read alias textFilePath before return) as integer
set selectedShape to shape n of selectedSlide
return selectedShape
end tell
end GetSelectedShape
 
S

Steve Rindsberg

I am trying to get a script that allows me to format text. Based on
the guide I have been trying the code below, but keep getting errors.

What's the text of the error and on what line does it occur?

The comments before and after this example code explain more about how it works
and why VBA was used.

An alternate approach might be to create a shape on the slide and set its text
to the value you want to return rather than writing the text out to a file (the
only part that uses VBA).
Could anyone guide me as to what is wrong?

Also, the code contains VBA - which seems to defeat the point - is
there a way to do it solely in AS?

many thanks,

Peter

tell application "Microsoft PowerPoint"
--get the selected shape via the handler
set selectedShape to my GetSelectedShape() -- paste it in!
tell text range of text frame of selectedShape
tell its font
set {font name, font size, font color, bold} to ¬
{"Arial", 24, {255, 0, 0}, true}
end tell
end tell
end tell

to GetSelectedShape()
set textFilePath to (path to temporary items as string) & "Shared
Text File"
tell application "Microsoft PowerPoint"
activate
set theIndex to slide index of slide of view ¬
of active window
set selectedSlide to slide theIndex of active presentation
do Visual Basic "n =
ActiveWindow.Selection.ShapeRange.ZOrderPosition
'write n as string to text file, replacing any text there
FileNumber = FreeFile
Open \"" & textFilePath & "\" For Output As #FileNumber
Print #FileNumber, CStr(n)
Close #FileNumber
"
set n to (read alias textFilePath before return) as integer
set selectedShape to shape n of selectedSlide
return selectedShape
end tell
end GetSelectedShape

================================================
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 
P

peterthebag

Hi,
the message is "microsoft powerpoint got an error:" with the script
editor highlighting VBA section of the code.

I have tried other approaches such as

tell application "Microsoft powerpoint"
go to first slide
select text
set font to palatino
end tell



this gives the error: Can't set «class PpFc» to palatino. Access not
allowed.

I also tried:

tell application "Microsoft PowerPoint"
set theShape to shape 1 of slide 1 of active presentation
tell theShape
set font to "arial"
end tell
end tell
but got: Can't set font to "arial". Access not allowed.

If I could get one of these to work and cycle through the slides - or
go to specific slides/headers that would be great.

Many thanks,

Peter
 
S

Steve Rindsberg

Hi,
the message is "microsoft powerpoint got an error:" with the script
editor highlighting VBA section of the code.

Are you using 2008, by any chance?
It doesn't support VBA at all ... that would account for the error, if so.

Otherwise which version?
I have tried other approaches such as

tell application "Microsoft powerpoint"
go to first slide
select text
set font to palatino
end tell

this gives the error: Can't set «class PpFc» to palatino. Access not
allowed.

I also tried:

tell application "Microsoft PowerPoint"
set theShape to shape 1 of slide 1 of active presentation
tell theShape
set font to "arial"
end tell
end tell
but got: Can't set font to "arial". Access not allowed.

If I could get one of these to work and cycle through the slides - or
go to specific slides/headers that would be great.

Many thanks,

Peter

================================================
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 
S

Steve Rindsberg

Hi,
sorry, its the latest update of 2004 running on 10.4.11, on a G5

No problem, and sorry back atcha for being so slow to respond. I kept hoping
I'd have time to try this out on the Mac but things haven't worked out that way
so far.

A question though ... since you're using 2004, is there a reason you can't just
write the whole thing in VBA?

================================================
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 
P

peterthebag

Hi,

I just can't see the point of VBA at this stage - they would need
converting later.

regards,

Peter
 
S

Steve Rindsberg

Hi,

I just can't see the point of VBA at this stage - they would need
converting later.

Just saw this, which contains some bits that might be of interest to you:

http://biz.yahoo.com/prnews/080513/aqtu077.html?.v=48

Note the SP1 fix that makes it possible to work with the current selection in
2008. I wonder if this means that it wasn't possible in 2004?



================================================
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 

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