Solved

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

Posted on 2016-09-10
9
140 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 250 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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 250 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Suggested Courses

622 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