Log in

View Full Version : VBA Powepoint Project Help



EdenC
05-14-2011, 02:29 AM
Hi Guys,

I have zero experince in VBA (although I do have experince in other languages eg. Python) and for a project in IT need to make a powerpoint.

I thought that I could easily create a few things witht the help of VBA but it turns out that its harder than I think.

Please could you help me with the following:

1 - I've created a "Whats Your Favourite Dish" section using option buttons which I have programmed to change what is in each section of the dish. For example, under vegatables I have three options, choosing carrots will change the vegatable variable to carrots and advance to the next slide. I also want it to increase a variable called price by a certain amount. How would I do this? (I tried "Price =+ 0.5" and "Price = Price + 0.5" but they didn't seem to work)

2 - After the options, the user should then get a message on a slide that says what his/her favourite meal contains and how much it would cost them. How would a write this so that the message appears in the slide and how does String Concatenation work in VBA?

A picture of my VBA code can be found when adding the following to the end of bitly: kNHmC1

My powerpoint can be download here (it looks crap on a large screen and uses custom fonts which you won't be able to see) (again bitly): iuUVTP

Thanks!

John Wilson
05-14-2011, 05:18 AM
Did you declare the variable Price and if so as what?

I would suggest this

Public price as Single
Sub PriceUp()
price = price + 0.5
End Sub
String cocantenation works like this

Dim strMyString As String
strMyString = "The start " & "the end"

EdenC
05-14-2011, 09:39 AM
Thanks John!

The last thing I need to do is to have that message entered onto a new slide. How would I print that string into a slide rather than a MsgBox?

John Wilson
05-14-2011, 11:30 AM
You will have to be more precise

Which version of PPT?

" A new slide"/
CREATE a new slide?
Into an existing slide?

Where do you want the text?
The title?
A text placeholder?
a standard textbox?
In a shape?

EdenC
05-15-2011, 01:57 AM
Sorry John, was rushing on my last post.

I'm using 2007 and need the text to be in a text box on a slide that I already have existing.

Sorry for the confusion and thanks for your help so far!
EDEN

John Wilson
05-15-2011, 02:10 AM
I would suggest that you NAME the textbox. You can do this from the HOME tab > Editing > Select > Selection Pane. You will see the default name which will be "TextBox x" if it really is a textbox, many people use this term when they really mean Text Placeholder which will be named Something Placeholder x.

Either way select the name in the selection pane and change to something useful "Target" for example.

Then:

ActivePresentation.Slides(1).Shapes("Target").TextFrame.TextRange = "whatever" ' or =strMyText
Obviously if it's not slide 1 change the number.

EdenC
05-15-2011, 02:20 AM
OK. Thanks John! Will be sure to give all this a go soon!