Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBScript in Powerpoint - Change Formatting in Text Box on a line-by-line basis

Posted on 2016-09-10
9
Medium Priority
?
168 Views
Last Modified: 2016-09-14
I want to be able to paste text and change the formatting of certain lines in an existing text box, named "author", on my powerpoint file.  I have a bank of authors that the user chooses from (1-10).  I have a Select Case setup to automatically assign values to variables I'm using to populate the text box with:

	
Case Else
  strEngName = "<author's name>"  'line 1
  strEngTitle = "<author's title>"  'line 2
  strPhone = "Office: <author's phone>"  'line 3
  strEmail = "Email: <author's email>"  'line 4

Open in new window


The first two lines are Black and Bold Italic, the next two lines are Gray and Italic.

The text box is existing and I'm just replacing placeholder text.
0
Comment
Question by:Mark DeMint
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 52

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 1000 total points
ID: 41793772
Hi,

pls try something like this
Sub Macro()
    Set txtrng = ActivePresentation.Slides(1).Shapes(1).TextFrame2.TextRange
    aLines = Split(txtrng.Text, Chr(11))
    first2Lines = aLines(0) & Chr(11) & aLines(1) & Chr(11)
    For Idx = 2 To UBound(aLines)
        RemainingLines = RemainingLines & Chr(11) & aLines(Idx)
    Next
    RemainingLines = Right(RemainingLines, Len(RemainingLines) - 1)
    txtrng.Characters(1, Len(first2Lines)).Font.Bold = msoTrue
    txtrng.Characters(1, Len(first2Lines)).Font.Fill.ForeColor.RGB = RGB(0, 0, 0)
    txtrng.Characters(Len(first2Lines) + 1, Len(txtrng.Text) - Len(first2Lines)).Font.Italic = msoTrue
    txtrng.Characters(Len(first2Lines) + 1, Len(txtrng.Text) - Len(first2Lines)).Font.Fill.ForeColor.RGB = RGB(217, 217, 217)
End Sub

Open in new window

depending which return you used you'll have to change chr(11) into chr(13)

Regards
1
 

Author Comment

by:Mark DeMint
ID: 41797047
Thanks, Rgonzo1971!  Where would I use the variables I listed above: strEngName, strEngTitle, strPhone, strEmail?

The user will select from a dialog which user they are (1-10) then the text box will automatically place the text and format it.  So I've got the formatting like you gave me above, but where do I get it to use values assigned to these variables for the content?
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 41797332
Without seeing the code I cannot say
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Mark DeMint
ID: 41797425
What else do you need to see?  At the top I shared a generic case that sets a variable equal to a string.  I just want to take the code you supplied and set the content in each line equal to those variables.  Then I would have your code format the text.
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 41797427
How do you reference the shape ?
Are the lines CHr(11) or CHr(13) separated?
0
 

Author Comment

by:Mark DeMint
ID: 41797431
Not at my work computer right now, but it was similar to how you referenced it, but I named the shape "author".

ActivePresentation.Slides(1).Shapes("author").TextFrame2

As far as the return goes I could use whichever is preferred.  I don't recall if it was chr(11) or chr(13), but I can change to either if need be.
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 41797434
my code should be afterwards since it format the first 2 lines then the 2 remaining lines
0
 
LVL 23

Accepted Solution

by:
JSRWilson earned 1000 total points
ID: 41798461
Maybe something based on this would work

Sub test()
Dim strEngName As String
Dim strEngTitle As String
Dim strPhone As String
Dim strEmail As String
Dim osld As Slide
Dim oshp As Shape
Dim P As Long

  strEngName = "<author's name>"  'line 1
  strEngTitle = "<author's title>"  'line 2
  strPhone = "Office: <author's phone>"  'line 3
  strEmail = "Email: <author's email>" 'line4
  Set osld = ActiveWindow.Selection.SlideRange(1)
  Set oshp = osld.Shapes("author")
  With oshp.TextFrame2.TextRange
.Text = strEngName & vbCrLf & strEngTitle & vbCrLf & strPhone & vbCrLf & strEngName
  For P = 1 To 2
  .Paragraphs(P).Font.Bold = True
  .Paragraphs(P).Font.Fill.ForeColor.RGB = vbBlack
  Next P
  For P = 3 To 4
  .Paragraphs(P).Font.Bold = False
  .Paragraphs(P).Font.Fill.ForeColor.RGB = RGB(127, 127, 127)
  Next P
  End With
End Sub

Open in new window

0
 

Author Closing Comment

by:Mark DeMint
ID: 41798633
Thank you both!  This was exactly what I was looking for.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Not only does Prezi allow you to create non-linear presentations, it also makes it easy to apply transition animations between your frames. Learn how to apply a fade-in transition to select items and entire frames in this tutorial Select "Edit Path"…
In addition to being a great web-based presentation tool, Prezi also makes it easy to save your presentation as a PDF to share with others as well. Learn how in this tutorial. Select the share icon from the top menu in your Prezi editor: Select "D…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question