+ Reply to Thread
Results 1 to 10 of 10

Need help to filter attachments to certain file extensions exp. .pdf, .xls, .las

Hybrid View

  1. #1
    Registered User
    Join Date
    01-18-2019
    Location
    Houston, Texas
    MS-Off Ver
    1812
    Posts
    16

    Need help to filter attachments to certain file extensions exp. .pdf, .xls, .las

    The Code works just need help with filtering the attachments to certain file extension for example (*.PDF, *.XLS, *.LAS) Thanks in advanced

    Dim OutApp As Object
        Dim xlSheet As Object
        Dim OutMail As Object
        Dim i As Long
        Dim SendTO As String
        Dim olInsp As Object
        Dim wdDoc As Object
        Dim oRng As Object
    
        SendTO = Range("W5").Value
        SendCC = Range("H36").Value
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
        Set xlSheet = ActiveWorkbook.Sheets("COG Inter-Curve-Lateral")
        xlSheet.Range("C7:I25").Copy
        
        On Error Resume Next
        With OutMail
            .To = SendTO
            .CC = SendCC
            .BCC = ""
            .Subject = Range("C1")
            Set olInsp = .GetInspector
            Set wdDoc = olInsp.WordEditor
            Set oRng = wdDoc.Range
            oRng.Collapse 1
            oRng.Paste
            For i = 23 To FileCount + 27
                .Attachments.Add (Range("W20").Value & "\" & Range("W" & i).Value)
            Next i
            .Display   'or use .Send
        End With
        On Error GoTo 0
        Range("A1").Select
        Application.CutCopyMode = False
    
        Set OutMail = Nothing
        Set OutApp = Nothing
        Set xlSheet = Nothing
        Set olInsp = Nothing
        Set wdDoc = Nothing
        Set oRng = Nothing
    End Sub

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,275

    Re: Need help to filter attachments to certain file extensions exp. .pdf, .xls, .las

    Possibly with...
            For i = 23 To FileCount + 27
                Select Case Right(Range("W" & i).Value, InStrRev(Range("W" & i).Value, ".") - 1)
                    Case Is = "PDF", "XLS", "LAS"
                        .Attachments.Add (Range("W20").Value & "\" & Range("W" & i).Value)
                End Select
            Next i

  3. #3
    Registered User
    Join Date
    01-18-2019
    Location
    Houston, Texas
    MS-Off Ver
    1812
    Posts
    16

    Re: Need help to filter attachments to certain file extensions exp. .pdf, .xls, .las

    Just tried the code you sent. it creates the email but with no attachments.

  4. #4
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,275

    Re: Need help to filter attachments to certain file extensions exp. .pdf, .xls, .las

    The code assumes the file's name is in Range("W" & i).

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  5. #5
    Registered User
    Join Date
    01-18-2019
    Location
    Houston, Texas
    MS-Off Ver
    1812
    Posts
    16

    Re: Need help to filter attachments to certain file extensions exp. .pdf, .xls, .las

    First Click on Attachments the choose file location, it will ask you once for file location (this will put the file location on cell (W20) then once again the search for the file on that same folder. file name will be on (W22:W42). Thanks for your help
    Attached Files Attached Files

  6. #6
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,275

    Re: Need help to filter attachments to certain file extensions exp. .pdf, .xls, .las

    Try this version...
            For i = 23 To FileCount + 27
                Select Case Right(Range("W" & i).Value, Len(Range("W" & i).Value) - InStrRev(Range("W" & i).Value, "."))
                    Case Is = "PDF", "XLS", "LAS"
                        .Attachments.Add (Range("W20").Value & "\" & Range("W" & i).Value)
                End Select
            Next i

  7. #7
    Registered User
    Join Date
    01-18-2019
    Location
    Houston, Texas
    MS-Off Ver
    1812
    Posts
    16

    Re: Need help to filter attachments to certain file extensions exp. .pdf, .xls, .las

    Same results as before it creates the email but no attachments. Thank you for being patient and for your help.

  8. #8
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,275

    Re: Need help to filter attachments to certain file extensions exp. .pdf, .xls, .las

    Try this...
            For i = 23 To FileCount + 27
                Select Case UCase(Right(Range("W" & i).Value, Len(Range("W" & i).Value) - InStrRev(Range("W" & i).Value, ".")))
                    Case Is = "PDF", "XLS", "LAS"
                        .Attachments.Add (Range("W20").Value & "\" & Range("W" & i).Value)
                End Select
            Next i

  9. #9
    Registered User
    Join Date
    01-18-2019
    Location
    Houston, Texas
    MS-Off Ver
    1812
    Posts
    16

    Re: Need help to filter attachments to certain file extensions exp. .pdf, .xls, .las

    Thank you for all your help that did the trick.

  10. #10
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,275

    Re: Need help to filter attachments to certain file extensions exp. .pdf, .xls, .las

    Glad to do 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. [SOLVED] Attachments with extensions .xls.xlsx will not open
    By Winon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-03-2019, 09:47 AM
  2. Hidden file extensions
    By simal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-15-2017, 07:33 AM
  3. [SOLVED] File Extensions
    By 1vision in forum Excel General
    Replies: 4
    Last Post: 05-19-2014, 04:35 PM
  4. File Open with two extensions
    By c.vaibhav in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2011, 03:36 AM
  5. file extensions
    By dottiea in forum Excel General
    Replies: 1
    Last Post: 07-27-2006, 11:20 AM
  6. [SOLVED] File Extensions
    By Robin Clay in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-25-2006, 11:55 PM
  7. [SOLVED] XML file extensions
    By Rowan in forum Excel General
    Replies: 2
    Last Post: 04-22-2005, 03:06 AM

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