PDA

View Full Version : Insert textbox inline or giving ids/names to textframes



raising
06-21-2015, 10:49 AM
​Hey!

I'm writing a macro that reads a citation from a text file. After it had been read I want to be able to add the citation string right after the text where the person was writing (and the flashing cursor is). The problem is that I need to keep track of the different citations that I added, because I want to be able to loop through all the citations that I added this way, and add them to a new slide with all the added citations.

The way I'm doing it now is by adding a textbox with the name "citationBox" to the current slide, and if the textbox already exists, I add the new strings to it aswell. This way I can loop through all the slides and check if it contains a shape called "citationBox" and copy its value to a new string that will contain all added citations.

The problem is that with textboxes I haven't found a way to add it inline on the position where the user was typing. I can add it inline just as a textrange, but then I'm not able to give the citation a name or id and thus can't find it anymore to add it to the slide that contains all citations.

Any ideas on how to solve my problem?


This is the code I use to make a new slide with the citations:

Dim pptSlide As Slide Dim pptLayout As CustomLayout
Dim sld As Slide
Dim shp As Shape
Dim citationString As String
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If (shp.name = "citationBox") Then
citationString = citationString & vbNewLine & shp.TextFrame.TextRange.text
End If
Next shp
Next sld
If ActivePresentation.Slides.Count > 1 Then
Set pptLayout = ActivePresentation.Slides(2).CustomLayout
Else
Set pptLayout = ActivePresentation.Slides(1).CustomLayout
End If
Set pptSlide = ActivePresentation.Slides.AddSlide((ActivePresentation.Slides.Count + 1), pptLayout)
pptSlide.Shapes.Title.TextFrame.TextRange.text = "References"
pptSlide.Shapes(2).TextFrame.TextRange = citationString

John Wilson
06-21-2015, 01:54 PM
Add the text inline but also add a slide tag Name= "CITATION1" Value="The text of the citation"


pptSlide.Tags.Add "CITATION1", "The text"

You can read this tag


MsgBox pptSlide.Tags("CITATION1")

raising
06-21-2015, 03:00 PM
Add the text inline but also add a slide tag Name= "CITATION1" Value="The text of the citation"


pptSlide.Tags.Add "CITATION1", "The text"

You can read this tag


MsgBox pptSlide.Tags("CITATION1")

Nice! That's quite handy, but is there a way of deleting the citation tag as well if the citation in the text would get deleted?

I wouldn't want citations to come up in the references list that were deleted from the slide again.

John Wilson
06-22-2015, 07:44 AM
No simple way to auto delete the tag no. If it was me I would make a ribbon button to add and remove citations but this would need to be a ppam AddIn.

Delete code

pptSlide.Tags.Delete("CITATION1")