Consulting

Results 1 to 6 of 6

Thread: Run-time eerror 424

  1. #1
    VBAX Newbie
    Joined
    Mar 2018
    Posts
    2
    Location

    Run-time eerror 424

    Hi forum!
    I found a VBA script in another thread to help me insert pictures with their filenames, but it's not working for me so I'm hoping someone can tweak it to get it to work, because coding COMPLETELY eludes me. No matter how hard I try.
    Here's what I've got:

    Sub PicWithCaption()
    Dim file
    Dim path As String
    path = "C:\Users\bianca.bianca-PC\Desktop\Barcodes"
    file = Dir(path & "*.*") ' ALL files
    
    CaptionLabels.Add Name:="Filename"
    
    Do While file <> ""
       ' test for extension
         If UCase(Right(file, 3)) = "PNG" Or _
            UCase(Right(file, 3)) = "TIF" Or _
           UCase(Right(file, 3)) = "JPG" Then
           With Selection
             .EndKey Unit:=wdStory
             .InlineShapes.AddPicture Filename:=path & file, _
              LinkToFile:=False, SaveWithDocument:=True
             .InsertAfter vbCrLf & vbCrLf
             .Collapse 0
             .MoveLeft Unit:=wdCharacter, Count:=1
             .Style = "Caption"
             .Text = path & file
          End With
        End If
        file = Dir()
    Loop
    
    Selection.EndKey Unit:=wdStory
    End Sub


    Here's what it does:
    I have the workbook saved as macro-enabled (.xlsm)
    I type Alt+F8, click on Run
    "Run-time error "424": Object required"
    Click on Debug
    It brings me back to the module where CaptionLabels.Add Name:="Filename" is highlighted.

    Any help would be appreciated!
    Last edited by SamT; 03-27-2018 at 07:05 AM.

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    This code is for Word, not Excel, which is why it doesn't work.
    Be as you wish to seem

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    CaptionLabels is not Declared
    Dim CaptionLabels As Collection
    This section is all about Word and does not apply in any way to Excel
    With Selection
             .EndKey Unit:=wdStory
             .InlineShapes.AddPicture Filename:=path & file, _
              LinkToFile:=False, SaveWithDocument:=True
             .InsertAfter vbCrLf & vbCrLf
             .Collapse 0
             .MoveLeft Unit:=wdCharacter, Count:=1
             .Style = "Caption"
             .Text = path & file
          End With
    You need to tell us exactly what you have on the Excel Sheet and what you are trying to accomplish in Excel, before we can help you.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Quote Originally Posted by SamT View Post
    CaptionLabels is not Declared
    Dim CaptionLabels As Collection
    CaptionLabels is a Word object.
    Be as you wish to seem

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Ahah.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    VBAX Newbie
    Joined
    Mar 2018
    Posts
    2
    Location
    Thank you!
    I have a blank workbook, I'm trying to insert pictures with their filenames as text.

Posting Permissions

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