473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Assign text to slides

Hi,
I am writing excel VBA program to make a popwerpoint presentation and assign predefined text to each slide depending on number. I am using if condition to check the image number and assigning text to slide.
Below is the code I have written -
Expand|Select|Wrap|Line Numbers
  1. Private Const imgSlide1 = "Example1"
  2. Private Const imgSlide2 = "Example2"
  3. Private Const imgSlide3 = "Example3"
  4. Private Const imgSlide4 = "Example4"
  5. imgCnt=1
  6. picCnt=9
  7. While imgCnt <= picCnt
  8.  
  9.  
  10.     ppApp.ActiveWindow.View.GotoSlide (slideNo)
  11.  
  12.     Set ppSlide = ppApp.ActivePresentation.Slides(slideNo)
  13.  
  14.     If imgCnt = 1 Then
  15.         ppSlide.Shapes(2).TextFrame.TextRange.Text = imgSlide1
  16.     ElseIf imgCnt = 2 Then
  17.         ppSlide.Shapes(2).TextFrame.TextRange.Text = imgSlide2
  18.     ElseIf imgCnt = 3 Then
  19.         ppSlide.Shapes(2).TextFrame.TextRange.Text = imgSlide3
  20.     ElseIf imgCnt = 4 Then
  21.         ppSlide.Shapes(2).TextFrame.TextRange.Text = imgSlide4
  22.     End If
  23.  
  24.     imgCnt = imgCnt + 1
  25.  
Here instead of IF...ELSE conditions I want to use like
Expand|Select|Wrap|Line Numbers
  1. imgCnt=1
  2. picCnt=9
  3. While imgCnt <= picCnt
  4.  
  5.  
  6.     ppApp.ActiveWindow.View.GotoSlide (slideNo)
  7.  
  8.     Set ppSlide = ppApp.ActivePresentation.Slides(slideNo)
  9.  
  10.     'Here for const 1,2,3,4 I want to user imgCnt variable value and will concate it to imSlide as shown below
  11.     'but it is not working 
  12.     ppSlide.Shapes(2).TextFrame.TextRange.Text = "imgSlide" & imgCnt
  13.  
  14.     imgCnt = imgCnt + 1
  15.  
But instead of imgSlide1 value it is taking "imgSlide1" as a value

Could you please let me know how to fix it.
Jun 18 '13 #1

✓ answered by Rabbit

Your thread has been moved to the Excel forum.

Arrays are a basic and broad subject. If you do not know what an array is, you may want to invest some time in a tutorial. you can find Microsoft's documentation on arrays here: http://msdn.microsoft.com/en-us/libr...ffice.10).aspx

5 2029
Mihail
759 512MB
Exactly. VB get to you what you have asking :)
So, you concatenate 2 strings. Logically, you obtain a new STRING, not the variable name. But, about this subject must talk a guy with a much better English than me.

If you wish to obtain Examle1, Example2, .... Example9 you must concatenate the string "Example" with imgCnt :
Expand|Select|Wrap|Line Numbers
  1.  ppSlide.Shapes(2).TextFrame.TextRange.Text = "Example" & imgCnt
But (I think) that is not the goal of your life to put an incremental number after the word "Example" as explanation for your pictures.
A better approach is to use a SELECT CASE statment:

Expand|Select|Wrap|Line Numbers
  1. Dim Txt As String
  2.  
  3.     ppApp.ActiveWindow.View.GotoSlide (slideNo)
  4.     Set ppSlide = ppApp.ActivePresentation.Slides(slideNo)
  5.  
  6.     While imgCnt <= picCnt
  7.         Select Case imgCnt
  8.             Case 1
  9.                 Txt = imgSlide1
  10.             Case 2
  11.                 Txt = imgSlide2
  12.             .......................
  13.             Case Else
  14.                 'Maybe code for trapping errors
  15.         End Select
  16.  
  17.         ppSlide.Shapes(2).TextFrame.TextRange.Text = Txt
  18.  
  19.         imgCnt = imgCnt + 1
  20.     End While ' Not sure about the syntax.
But why to type all that Private Const bla bla statements ?
So, a better approache:
Expand|Select|Wrap|Line Numbers
  1. 'No more need to declare constants
  2. Dim Txt As String
  3.  
  4.     ppApp.ActiveWindow.View.GotoSlide (slideNo)
  5.     Set ppSlide = ppApp.ActivePresentation.Slides(slideNo)
  6.  
  7.     While imgCnt <= picCnt
  8.         Select Case imgCnt
  9.             Case 1
  10.                 Txt = "Example1"
  11.             Case 2
  12.                 Txt = "Example2"
  13.             .......................
  14.             Case Else
  15.                 'Maybe code for trapping errors
  16.         End Select
  17.  
  18.         ppSlide.Shapes(2).TextFrame.TextRange.Text = Txt
  19.  
  20.         imgCnt = imgCnt + 1
  21.     End While ' Not sure about the syntax.
There are also other approaches (better) but I think that is enough for a very beginner.

That is about using VBA.
But I have a question:
Any approach require to manually type the explanation for every picture.
So... where is the benefit to use VBA ? You can type the explanation directly in the slide, isn't it ?

Cheers !
Jun 22 '13 #2
Mihali thanks for answering the question.
Regarding your question - I have written a macro this will take a screen shot of graphs from the webpage and it will create a powerpoint presentation.
There are total 37 graphs but we don't know how many screen shots we are going to take(it can be 10,12,15 etc)
We know the name of the graphs hence I am planning to declare 37 constant and will ask user to open the graph in sequence as their names are declared. Except opening the graphs on webpage rest of the process is automated hence we can not type directly on slide.
I don't want 37 cases or 37 else if conditions hence I post this question to find out any alternate way.

Hope this clear your doubt.
Jun 24 '13 #3
Rabbit
12,516 Expert Mod 8TB
Use an array.
Jun 24 '13 #4
Rabbit, could you please tell how to use it.
Jun 25 '13 #5
Rabbit
12,516 Expert Mod 8TB
Your thread has been moved to the Excel forum.

Arrays are a basic and broad subject. If you do not know what an array is, you may want to invest some time in a tutorial. you can find Microsoft's documentation on arrays here: http://msdn.microsoft.com/en-us/libr...ffice.10).aspx
Jun 25 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mike C. Fletcher | last post by:
Slides from my PyGTA presentation on Tuesday, focusing mostly on why/where you would want to use meta-classes, are available in PDF format: ...
3
by: warda | last post by:
Hi every one Are you aware of any c++ material slides that can be used to teach first year computer students Thanks
2
by: Will Chamberlain | last post by:
I'm trying to populate a label that is located in the Footer Template of my DataGrid. I want this to be displayed in a label instead of a textbox when the user wants to add a new record because I...
3
by: Woody Splawn | last post by:
I have been experimenting with Auto Slides and TreeViews and find them most usefull in Winforms. I know how to create a Treview and have it, for example, slide out from the left of my Winform but...
6
by: Johnny Holland | last post by:
Hi, I am working on a presentation tool (Powerpoint like) that allows the user to display text over a picture background. One of the best ways to make the text stand out would be to put a black...
3
by: ghadley_00 | last post by:
Hi, I have a MS access database into which I need to import a text file that is oriented vertically (fields are listed from top to bottom with the value for each field appearing to the right of...
1
by: | last post by:
I have a label control that I've embedded in a datalist template. I will be binding data to that label. I want to run a string formatting function on the database text before it is injected into...
2
by: rachit.goyal | last post by:
Hi All, I am using .net first time.In my windows form VC7 application, on a click of button, I am assigning text of TextBox to STL string varibale. Using this code- private: System::Void...
2
by: Durgaaa | last post by:
how to assing text to a label
0
by: tushariiit | last post by:
I am building a ppt viewer sort of thing by reading a text file.I am able to display text indesirable format but problem is that I am using RichTextCtrl to display my output on screen.and for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.