Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Applications / PowerPoint / May 2008



Tip: Looking for answers? Try searching our database.

VBA to Applescript in PPT

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
peterthebag@yahoo.com - 09 May 2008 17:03 GMT
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
Steve Rindsberg - 09 May 2008 21:31 GMT
> 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?
>
[quoted text clipped - 37 lines]
>  end tell
> end GetSelectedShape

================================================
Steve Rindsberg, PPT MVP
PPT FAQ:  www.pptfaq.com
PPTools:  www.pptools.com
================================================
peterthebag@yahoo.com - 09 May 2008 22:47 GMT
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
Steve Rindsberg - 10 May 2008 05:40 GMT
> 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
>
[quoted text clipped - 23 lines]
>
> Peter

================================================
Steve Rindsberg, PPT MVP
PPT FAQ:  www.pptfaq.com
PPTools:  www.pptools.com
================================================
peterthebag@yahoo.com - 10 May 2008 08:49 GMT
Hi,
sorry, its the latest update of 2004 running on 10.4.11, on a G5

Peter
Steve Rindsberg - 12 May 2008 21:24 GMT
> 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
================================================
peterthebag@yahoo.com - 13 May 2008 09:11 GMT
Hi,

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

regards,

Peter
Steve Rindsberg - 13 May 2008 22:01 GMT
> 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
================================================
peterthebag@yahoo.com - 10 May 2008 09:05 GMT
hi,
it is office 2004, on 10.4.11, on a G5.

thanks.
PtB
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.