Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-14-2019, 03:31 PM
KarenK13 KarenK13 is offline PowerPoint macro to change words between quotes to italic needed Windows 10 PowerPoint macro to change words between quotes to italic needed Office 2013
Novice
PowerPoint macro to change words between quotes to italic needed
 
Join Date: Jul 2019
Posts: 6
KarenK13 is on a distinguished road
Default PowerPoint macro to change words between quotes to italic needed

Hello,

PowerPoint does not offer the same detailed features in Find & Replace as Word does. It also doesn't accept wild cards.

Therefore, I'm looking for a PowerPoint macro to change all words between quotes to italic. Would anyone be able to help?

Thanks,



Karen
Reply With Quote
  #2  
Old 07-15-2019, 05:23 AM
JohnWilson JohnWilson is offline PowerPoint macro to change words between quotes to italic needed Windows 10 PowerPoint macro to change words between quotes to italic needed Office 2016
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,912
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

Not easy!

Here's a possible start for you to work on if you have multiple quotes in one textframe you will need to work on the pattern.

Code:
Sub regxz()

Dim oMatches As Object
Dim i As Long
Dim otr As TextRange2
Dim osld As Slide
Dim oshp As Shape
Dim regX As Object
Dim strmatch As String
Set regX = CreateObject("VBScript.RegExp")

' this allows for smart curly quotes but do not mix smart and straight
strmatch = "[" & Chr(147) & "," & Chr(34) & "]" & ".*" & "[" & Chr(148) & "," & Chr(34) & "]"
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.HasTextFrame Then
If oshp.TextFrame2.HasText Then Set otr = oshp.TextFrame2.TextRange
On Error Resume Next
With regX
    .Global = True
    .IgnoreCase = True
    .Pattern = strmatch
    Set oMatches = .Execute(otr)
    For i = 0 To oMatches.Count - 1
       otr.Characters(oMatches(i).FirstIndex + 1, Len(oMatches(i).Value)).Font.Italic = True
    Next i
End With
End If
Next oshp
Next osld
End Sub
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
  #3  
Old 07-15-2019, 06:51 AM
KarenK13 KarenK13 is offline PowerPoint macro to change words between quotes to italic needed Windows 10 PowerPoint macro to change words between quotes to italic needed Office 2013
Novice
PowerPoint macro to change words between quotes to italic needed
 
Join Date: Jul 2019
Posts: 6
KarenK13 is on a distinguished road
Default

Quote:
Originally Posted by JohnWilson View Post
Not easy!

Here's a possible start for you to work on

Code:
Sub regxz()

Dim oMatches As Object
Dim i As Long
Dim otr As TextRange2
Dim osld As Slide
Dim oshp As Shape
Dim regX As Object
Dim strmatch As String
Set regX = CreateObject("VBScript.RegExp")

' this allows for smart curly quotes
strmatch = "[" & Chr(147) & "," & Chr(34) & "]" & ".*" & "[" & Chr(148) & "," & Chr(34) & "]"
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.HasTextFrame Then
If oshp.TextFrame2.HasText Then Set otr = oshp.TextFrame2.TextRange
On Error Resume Next
With regX
    .Global = True
    .IgnoreCase = True
    .Pattern = strmatch
    Set oMatches = .Execute(otr)
    For i = 0 To oMatches.Count - 1
       otr.Characters(oMatches(i).FirstIndex + 1, Len(oMatches(i).Value)).Font.Italic = True
    Next i
End With
End If
Next oshp
Next osld
End Sub
Hi John,

You are absolutely amazing!!! I spent hours searching the internet and trying macros but I didn't know how to manipulate the code for italic.

This worked perfectly!!! Thanks so much!!!

Karen
Reply With Quote
  #4  
Old 07-15-2019, 07:03 AM
JohnWilson JohnWilson is offline PowerPoint macro to change words between quotes to italic needed Windows 10 PowerPoint macro to change words between quotes to italic needed Office 2016
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,912
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

You should probably use ".*?" instead of ".*" BTW to turn off a greedy match
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
  #5  
Old 07-18-2019, 08:57 AM
KarenK13 KarenK13 is offline PowerPoint macro to change words between quotes to italic needed Windows 10 PowerPoint macro to change words between quotes to italic needed Office 2013
Novice
PowerPoint macro to change words between quotes to italic needed
 
Join Date: Jul 2019
Posts: 6
KarenK13 is on a distinguished road
Default

Hi John,

I'm sorry to disturb you. The macro works great if copy is in a text box by itself. My colleague that designs the slides creates a shape then inserts the text box within the shape and all shapes are grouped on the one slide. Is there a way to manipulate the code to get within those shapes? Thanks so much for your assistance.

Karen
Reply With Quote
  #6  
Old 07-18-2019, 09:21 AM
JohnWilson JohnWilson is offline PowerPoint macro to change words between quotes to italic needed Windows 10 PowerPoint macro to change words between quotes to italic needed Office 2016
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,912
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

You could try something based on this:

Code:
Sub regxz()

Dim L As Long
Dim otr As TextRange2
Dim osld As Slide
Dim oshp As Shape
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
Select Case oshp.Type
Case Is = msoGroup
For L = oshp.GroupItems.Count To 1 Step -1
If oshp.GroupItems(L).HasTextFrame Then
If oshp.GroupItems(L).TextFrame2.HasText Then Set otr = oshp.GroupItems(L).TextFrame2.TextRange
End If
Call fixTR(otr)
Next L
Case Else
If oshp.HasTextFrame Then
If oshp.TextFrame2.HasText Then Set otr = oshp.TextFrame2.TextRange
Call fixTR(otr)
End If
End Select
Next oshp
Next osld
End Sub

Sub fixTR(otr As TextRange2)
On Error Resume Next
Dim oMatches As Object
Dim i As Long
Dim regX As Object
Dim strmatch As String
strmatch = "[" & Chr(147) & "," & Chr(34) & "]" & ".*?" & "[" & Chr(148) & "," & Chr(34) & "]"
Set regX = CreateObject("VBScript.RegExp")
With regX
    .Global = True
    .IgnoreCase = True
    .Pattern = strmatch
    Set oMatches = .Execute(otr)
    For i = 0 To oMatches.Count - 1
       otr.Characters(oMatches(i).FirstIndex + 1, Len(oMatches(i).Value)).Font.Italic = True
    Next i
End With
End Sub
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
  #7  
Old 08-21-2019, 03:13 PM
KarenK13 KarenK13 is offline PowerPoint macro to change words between quotes to italic needed Windows 10 PowerPoint macro to change words between quotes to italic needed Office 2013
Novice
PowerPoint macro to change words between quotes to italic needed
 
Join Date: Jul 2019
Posts: 6
KarenK13 is on a distinguished road
Default

Hi John,

I had a new report and tried the macro. It changed words in quotes to italic which I needed but it also changed words between commas to italic. Can that be fixed?

Thanks so much,

Karen
Reply With Quote
  #8  
Old 08-22-2019, 08:02 AM
JohnWilson JohnWilson is offline PowerPoint macro to change words between quotes to italic needed Windows 10 PowerPoint macro to change words between quotes to italic needed Office 2016
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,912
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

I'm out of Office right now but try replacing

strmatch = "[" & Chr(147) & "," & Chr(34) & "]" & ".*?" & "[" & Chr(148) & "," & Chr(34) & "]"

WITH

strmatch = "[" & Chr(147) & "|" & Chr(34) & "]" & ".*?" & "[" & Chr(148) & "|" & Chr(34) & "]"
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
  #9  
Old 08-22-2019, 12:50 PM
KarenK13 KarenK13 is offline PowerPoint macro to change words between quotes to italic needed Windows 10 PowerPoint macro to change words between quotes to italic needed Office 2013
Novice
PowerPoint macro to change words between quotes to italic needed
 
Join Date: Jul 2019
Posts: 6
KarenK13 is on a distinguished road
Talking

Hi John,

That seems to have worked. You're amazing!!! Thank you so much!!!

Karen
Reply With Quote
  #10  
Old 01-12-2020, 12:59 PM
KJSK71 KJSK71 is offline PowerPoint macro to change words between quotes to italic needed Windows 10 PowerPoint macro to change words between quotes to italic needed Office 2019
Novice
 
Join Date: Jan 2020
Posts: 2
KJSK71 is on a distinguished road
Default

John, Karen told me you are amazing and I need some help in excel. I posted it in the excel forum, but if you have time...would greatly appreciate your expertise.

https://www.msofficeforums.com/excel...tml#post147953
Thank you Kevin
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro needed to copy Powerpoint presentation and sections Marrick13 PowerPoint 0 06-19-2017 07:34 AM
PowerPoint macro to change words between quotes to italic needed Help Needed with Macro to Change Formulas to Text Using Ranges rsrasc Excel Programming 2 11-29-2016 02:31 PM
PowerPoint macro to change words between quotes to italic needed How to replace straight quotes with smart quotes in existing document PABwriter Word 4 05-27-2016 03:36 PM
PowerPoint macro to change words between quotes to italic needed repel Macro vba help is needed for interactive powerpoint. Mrs Blobby PowerPoint 1 04-16-2014 10:58 PM
PowerPoint macro to change words between quotes to italic needed Regular Expressions: match words within quotes? tinfanide Word VBA 3 02-02-2013 10:07 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:10 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft