Consulting

Results 1 to 4 of 4

Thread: Insert textbox inline or giving ids/names to textframes

  1. #1
    VBAX Newbie
    Joined
    Jun 2015
    Posts
    2
    Location

    Cool Insert textbox inline or giving ids/names to textframes

    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

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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")
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Newbie
    Joined
    Jun 2015
    Posts
    2
    Location
    Quote Originally Posted by John Wilson View Post
    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.

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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")
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •