Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-09-10
9
Medium Priority
?
183 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
  • 4
  • 4
9 Comments
 
LVL 53

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 53

Expert Comment

by:Rgonzo1971
ID: 41797332
Without seeing the code I cannot say
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 53

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 53

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

886 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