VBA PowerPoint - fill in textbox based on another textbox content on different slide - vba

I am a beginner with VBA, and I was wondering whether VBA could help me to automate presentation creation process.
My presentation template has on the top of each slide a textbox, which I would like to fill in with the text from a different slide.
Example:
Slide 1 (Divider slide): includes only 1 textbox with text e.g. 1) Project scope
Slide 2, 3, 4 ... (Content slides): include title, charts, other text box, etc. - but also 1 "descriptive" textbox placed always in the same place on the top of each slide
I would like this "descriptive" textbox to include text from Slide 1 (Divider slide).
Text in the "descriptive" textbox would change every time a new Divider slide would be detected, i.e. different "descriptive" textbox for each presentation part.
Not sure whether this can be done with VBA as I could not find anything similar online.
Thank you a lot for any information!

Related

Change the color of a selected record in an Access REPORT

My Access REPORT has a text box with the Record ID that looks like a button with an on click event to go to a form for that specific record. This works great, but when I return to the report I cannot see which record was clicked. I want to temporarily change ONLY the record that was clicked until another record is selected.
The reason I want this on a report and not a form is because I want the user to have a quick way to proof read in the format needed to print, and make a change or check a detail if necessary, then update the report AFTER all proof reading and updates are completed and before final print. But with many records on the screen it is easy to lose track of which record you were checking when returning from the form.
I tried:
Private Sub btn_txt_GoToTransaction_Click()
Dim vColor
vColor = RGB(51, 204, 51) 'green
Me.btn_txt_GoToTransaction.BackColor = vColor
DoCmd.OpenForm "Account_frm", acNormal, , "[TransactionID]=" & Me.TransactionID
End Sub
But this does not work because every button turns color not just the selected record.
Any suggestions? Thanks.
This is a great question because there are many benefits to highlighting a row or item in an Access Report. You are not able to just change the button color in one row only, but you can highlight the whole row so the user knows where they were.
Here are two methods to accomplish this:
Method 1 - Click on a Label
This works great in newer versions of MS Access when using Report View. Use a Label Control instead of a Button. You could make the label look like a button if you format it that way. I prefer to stretch an invisible Label across the whole row on top of all the other controls in that row. Then if you click anywhere in the row, it automatically selects that row and then runs whatever code you have in the OnClick Event. This works best if the Label is not linked to a Text Box.
This picture shows an example of how this method looks. You can click anywhere in the row and it highlights that row with the red outline and grey background.
This is very simple and works well but there are a couple disadvantages:
1- You can not change the color of the highlight.
2- If any of the text boxes CanGrow, the row height may be higher then the Label and create areas where the invisible label doesn't capture your click.
3- Clicking on a Text box does not work for this method.
Method 2 - Change Color of a Text Box
In order to just highlight one row or one piece of data in a report, we can use the "FormatConditions" property. This is the same as Conditional Formating from the MS Access design interface but we are going to change it programmatically on the fly. You can't do this with a button or label - it needs to be a Text Box with unique data, such as your TransactionID.
This picture shows an example of how this method looks. You can set the color of the highlight if you follow the steps below.
STEP 1) I recommend that you add a text box to your report that stretches from the left to the right, set the Back Color and Fore Color to White, set the Control Source to TransactionID, and set the Name to TransactionID. Then right click on this text box and select Position > Send To Back. This works best if the other text boxes and labels on the report have a transparent background.
STEP 2) Add this code:
Private Sub HightlightRow(intRowID As Integer)
With Me.TransactionID.FormatConditions
.Delete
With .Add(acFieldValue, acEqual, intRowID)
.BackColor = vbGreen
.ForeColor = vbGreen
End With
End With
End Sub
STEP 3) Also change your button code to call this subroutine like this:
Private Sub btn_txt_GoToTransaction_Click()
HightlightRow Me.TransactionID.Value
DoCmd.OpenForm "Account_frm", acNormal, , "[TransactionID]=" & Me.TransactionID
End Sub
STEP 4) I like to set it up so if the user clicks anywhere in the row, it will pop up with a modal with more detail regarding that row. Also, the user can't make any changes to the data in the Report View, so I use the pop up modal to allow changes. To accomplish this, I do a couple more things:
First, we need to add the code to the OnClick event for every control in that row. Ofcourse, each OnClick event will simply can that subroutine HightlightRow Me.TransactionID.Value
Second, if the user clicks on a Text Box, the Text Box gets the focus and hides the highlight. Therefore, I like to set the focus to something else. In your case, you could set the focus to the button by adding this line to the end of the HighlightRow subroutine: btn_txt_GoToTransaction.SetFocus
In my case, I am not using a button, so I set up a tiny Text Box with = " " (just an equal sign a space in quotation marks) as the Control Source. Then I position this tiny Text Box to the far right. And in the HighlightRow subroutine, I set the focus to this textbox.
STEP 5) You may also want a button or method of removing the highlight. To do that simply have the code run this line:
Me.TransactionID.FormatConditions.Delete

How to get the Text from Text Box which is clicked, by using VBA?

I'm working on a Presentation where I have a tabular form of information, where every first column cells have text which function, and I want to get that text from the cell so that I can do something based on the Text.
Here is the function which can help me get the name of the object which is clicked.
Sub getText(oShape)
MsgBox oShape.Name
End Sub
Here is the
You'll see Text Box with text One Two Three, every word has VBA function given to it. Now what I want is when someone clicks any word, it tells which word is clicked.

How to find the label of a shape on a Powerpoint slide

Can someone please point me in the right direction to finding the label Powerpoint uses for each shape, active x control, etc... I've researched till I'm blue in the face. Here's what I'm talking about:
I have a very simple slideshow that asks a question in a text box. Just below the question I placed an active x control text box to get the user's answer. All I want to do is take the answer and append it to a text file. Here's the code:
Public Sub WriteAnswerToFile(slideNum As Integer, shapeNum As String)
Dim filePath As String
Dim objFSO As FileSystemObject
Dim objFile As Variant
filePath = "C:\Batch Files\Powerpoint\ButtonPushes\AnswerFile.txt"
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Batch Files\Powerpoint\ButtonPushes\AnswerFile.txt", ForAppending)
objFile.WriteLine (Application.ActivePresentation.Slides(slideNum).Shapes(shapeNum).TextFrame.TextRange)
objFile.Close
End Sub
From each slide, I pass the slide number and the shape designator to the sub routine. The shapeNum is a string because I found that it worked (no better reason than that) for me to pass something like "TextBox 1" as the param. It all works absolutely great if I know the Shape(designator); as in Shape(TextBox1). For the life of me I cannot figure out how to pass the text input by the user into the active x control text box. I have no idea what the designator is. The property sheet for the text input box calls it TextBox1. The Code sheet calls it TextBox1. When I pass that parameter, it prints the question I asked, not the answer, to my text file. I don't know how to call the input text box in my code.
My code prints "How did you hear about us?" to my text file when my code runs with Call WriteAnswerToFile(2, "TextBox 1"). I'm sure that textbox is called textbox 1; it's the first textbox on the slide. I just don't know what Powerpoint labels the user input box.
If there is some sort of Powerpoint scripting or layout page that will define all the shapes in the slidewhow, I'd sure like to be pointed that direction.
You just need to refer to the form part of the Object since this is not a normal shape.
objFile.WriteLine (Application.ActivePresentation.Slides(slideNum).Shapes(shapeNum).OLEFormat.Object.Text)
To clarify from your comment. I think that you have two "Text Box 1". One is "TextBox 1" (note the space) which is the normal textbox and the ActiveX control is "TextBox1" (no space).
If I create a new blank slide and first add a normal text box and then an ActiveX textbox and then run the following code:
For Each shp In Slide2.Shapes
Debug.Print shp.Name
Next shp
The Immediate window will show the following:
TextBox 1
TextBox1
By chance I happened to stumble upon the simplest answer to my question of "finding the label Powerpoint uses for each shape, active x control, etc.."
I am using the Office 16 (Office 365) suite that contains Powerpoint and would not be certain this feature is avaiable to other versions.
On the Home tab in Powerpoint there is an Editing submenu that contains a Select function. As pictured here:
When you click on Select, another submenu appears that shows a Selection Pane function. If you click on that, the selction pane shows up on the right hand of the screen. In that pane you will see all of the objects on the current slide and the names Powerpoint has given to each of them.
It shows there, the discrepancy I was having with calling TextBox(Space)1 and TextBox(NoSpace)1.
This works to be much more expedient for me to grab the name of the shape I want to call in my VBS Scripts.
I am thankful; however, for the time and frustration #Diederik Sieburgh saved me in allowing me to move forward with my project as it is now 2 weeks later that I stumbled upon this information.

How to assign Textshape 1 as the title?

With Office 2016 PPT, after sharing a PPT file and getting it back, it now has retained titles on the slides but they are now "TextShape 1", are in the correct location (top of slide), and do not show up as titles in the outline view, etc.
Merely resetting the slides overlays empty boxes.
How can I make "TextShape 1" on each of the slides to be seen as the Title for the respective slides? A redefinition? Add a new Title box with the content of "TextShape 1", and delete the old box?
Thanks for the views.
It was not easy as a vba-powerpoint beginner finding my way through the collections and terminology, and certainly time consuming, but I wrote a solution for the limited problem as presented.
You might think you could add a title object, but at least the way I tried, it complained that that could not be done with the current slide layout. I could not figure out how to designate a text box as a Title. So I used vba to set the formats to Titleonly for slides without one, copied the text into it, then deleted the old shape that was overlaid with the new one as below:
Attribute VB_Name = "Module1"
Sub newtitles()
Dim s As Variant
For s = 1 To ActivePresentation.Slides.Count
If Not ActivePresentation.Slides(s).Shapes.HasTitle Then
ActivePresentation.Slides(s).Layout = ppLayoutTitleOnly
' adds a title placeholder too; could not .addtitle to slide without a title in format
ActivePresentation.Slides(s).Shapes.Title.TextFrame.TextRange.Text = ActivePresentation.Slides(s).Shapes(1).TextFrame.TextRange.Text
ActivePresentation.Slides(s).Shapes(1).Delete ' remove redundant box
End If 'about title
Next ' slides
End Sub

Add text to powerpoint slide using vba

I have PowerPoint with a slide master set so all slides have same characteristics. I want to use VBA to place the SlideIndex number of the corresponding slide on each side.
As of now I have it so when you click a button, the slide index pops up in a message box but I want it to pop up in a text box or something on the slide itself.
Here is the script I am currently using..
Private Sub CommandButton_Click()
MsgBox SlideShowWindows(1).View.Slide.SlideIndex
End Sub
I do not want to use a button. I want to automatically have it on each slide when its ran..Thanks in advance
Add a text box to one slide. While it's selected, type this in the Immediate window to name it something meaningful to you:
ActiveWindow.Selection.ShapeRange(1).Name = "SlideNumber"
Then your button handling code can look like:
With SlideShowWindows(1).View.Slide.SlideIndex.Shapes("SlideNumber")
.TextFrame.TextRange.Text = Cstr(SlideShowWindows(1).View.Slide.SlideIndex)
End with
By the way, you don't need VBA for this.
Go to the slide master view. On the master, add a text box wherever you want the slide index to appear.
While you have the text insertion cursor active, choose: Insert | Slide Number