+ Reply to Thread
Results 1 to 10 of 10

Error: Item Text not found in Shapes Collection

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Exclamation Error: Item Text not found in Shapes Collection

    Hi, all

    I have this one code where it can generate PowerPoint presentation from content in Excel, specified in pre-defined sheet, named Definitions in the Excel file. There is something wrong with 2 lines of code:

     sld.Shapes(PPObjName).TextFrame.TextRange.Text = _
                    Replace(sld.Shapes(PPObjName).TextFrame.TextRange.Text, OldText, NewText)
    This specific line is supposed to detect old text in textbox in the specific PowerPoint page but I have tried several trials and the same error showed up:

    Capture.PNG

    Can I know the reason why? Hereby I attached both PPT template and the Excel file: https://drive.google.com/open?id=1vH...2WwImuoosZHsrC

    Full code:

    Option Explicit
    
    Sub MakePowerpoint()
    Dim MyPath As String
    Dim FileName As String
    
    Dim objPPT As Object
    Dim ppt As Object
    Dim sld As Object
    Dim shp As Object
    Dim PPName As String
    Dim shpIndex As Long
    Dim CurSlide As Long
    
    Dim sh As Excel.Worksheet
    Dim ObjName As String
    Dim ObjType As String
    Dim PPSldNum As Long
    Dim PPObjName As String
    Dim MyTop As Double
    Dim MyLeft As Double
    Dim MyHeight As Double
    Dim MyWidth As Double
    Dim cl As Range
    Dim OldText As String
    Dim NewText As String
    
    ' Set up the pathname and the output PowerPoint Presentation Name
    MyPath = ThisWorkbook.Path
    PPName = MyPath & "\" & Range("PPReport_Name")
    
    ' Copy the template file to the PowerPoint Presentation Name
    FileCopy MyPath & "\" & Range("PPTemplate_Name"), PPName
    
    ' Open the PowerPoint Presentation
    Set objPPT = CreateObject("PowerPoint.Application")
    objPPT.Visible = True
    objPPT.Presentations.Open PPName
    
    Set ppt = objPPT.activepresentation
    
    ' Add objects
    For Each cl In Range("Table_Objects[Excel Page]")
        ObjType = cl.Offset(0, 2).Value     ' Type of the thing to copy
        If ObjType <> "Text" Then
            Set sh = Sheets(cl.Value)       ' Excel Sheet
            ObjName = cl.Offset(0, 1).Value ' Name of the thing to copy
        End If
        
        PPSldNum = cl.Offset(0, 3).Value    ' PowerPoint slide number
        PPObjName = cl.Offset(0, 4).Value   ' PowerPoint object
        MyTop = cl.Offset(0, 5).Value       ' Top
        MyLeft = cl.Offset(0, 6).Value      ' Left
        MyHeight = cl.Offset(0, 7).Value    ' Height
        MyWidth = cl.Offset(0, 8).Value     ' Width
        OldText = cl.Offset(0, 9).Value     ' Old Text
        NewText = cl.Offset(0, 10)          ' New Text
        
        Set sld = ppt.slides(PPSldNum)      ' Active Slide
        
        Select Case ObjType
            Case "Text"
                sld.Shapes(PPObjName).TextFrame.TextRange.Text = _
                    Replace(sld.Shapes(PPObjName).TextFrame.TextRange.Text, OldText, NewText)
            Case "Chart"
                sh.Shapes(ObjName).CopyPicture
            Case "Range"
                sh.Range(ObjName).CopyPicture
            Case "Cell"
                sh.Range(ObjName).Copy
        End Select
        
        If ObjType = "Chart" Or ObjType = "Range" Then
            sld.Shapes.Paste
            shpIndex = sld.Shapes.Count
            With sld.Shapes(shpIndex)
                .LockAspectRatio = msoFalse
                .Top = 72 * MyTop
                .Left = 72 * MyLeft
                .Height = 72 * MyHeight
                .Width = 72 * MyWidth
            End With
        End If
        If ObjType = "Cell" Then
            'sld.Shapes.Paste
            sld.Shapes.PasteSpecial 0
            shpIndex = sld.Shapes.Count
            With sld.Shapes(shpIndex)
                .LockAspectRatio = msoFalse
                .Top = 72 * MyTop
                .Left = 72 * MyLeft
                .Height = 72 * MyHeight
                .Width = 72 * MyWidth
           End With
        End If
    Next
    
    Application.CutCopyMode = False
    
    End Sub
    
    Function GetText(ObjName As String, Pos As Long) As String
    Dim cl As Range
    Dim Result As String
    
    Result = "Value not found"
    
    For Each cl In Range("Table_TextFrame[PPObjName]")
        If cl.Value = ObjName Then
            Result = cl.Offset(0, Pos).Value
            Exit For
        End If
    Next
    GetText = Result
    End Function

  2. #2
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Error: Item Text not found in Shapes Collection

    Anyone know what might contribute to the error above? Thanks in advance!

  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Error: Item Text not found in Shapes Collection

    You are using the name "Text" (in the variable PPObjName) to locate the shape in the slide, but none of the shapes have that name.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  4. #4
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Error: Item Text not found in Shapes Collection

    I have added textboxes in Slide 1 in the template.pptx. As per my understanding, the textboxes = "Text", isn't it? Or my understanding is wrong?

    FYI, I'm not the creator of this code. Still new to VBA, hence I did not understand the code entirely. Hoping for enlightenment from your side. Thanks in advance!

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Error: Item Text not found in Shapes Collection

    No. You have to refer to them by name- e.g. TextBox1 or TextBox2.

  6. #6
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Error: Item Text not found in Shapes Collection

    Can I know how to name the textbox or how to check the name of the textbox?

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Error: Item Text not found in Shapes Collection

    On the Home tab in PowerPoint, look in the Editing group on the right hand end of the ribbon, and click the Select dropdown, then choose Selection Pane. You can then see and edit the names of all the objects in the slide.

  8. #8
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Error: Item Text not found in Shapes Collection

    Meaning, if the textbox is named as Textbox1 in PPT template, I should insert "Textbox1" in the code?

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Error: Item Text not found in Shapes Collection

    You should enter TextBox1 in the relevant row in your sheet.

  10. #10
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Error: Item Text not found in Shapes Collection

    Thank you so much for the explanation! Really appreciate it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Cross post :how to fix the error -Method 'item'of the object 'shapes'failed'?
    By balajisx in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-12-2017, 11:10 AM
  2. Replies: 0
    Last Post: 12-08-2014, 06:46 AM
  3. Run-time error '-2147024809 (80070057)' Item with specified name wasn't found
    By tom_6030 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-08-2014, 10:24 PM
  4. [SOLVED] run time error '3265'; item cannot be found in the collection corresponding to the regues
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-08-2014, 03:29 AM
  5. Replies: 2
    Last Post: 05-13-2014, 07:07 AM
  6. [SOLVED] Run Time Error 3265 - Item not found in this collection
    By Sc0tt1e in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-23-2013, 07:19 AM
  7. Replies: 1
    Last Post: 11-17-2012, 11:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1