+ Reply to Thread
Results 1 to 2 of 2

Specifying an email address and folder name(Not default) if i have more than 1 email addre

Hybrid View

  1. #1
    Registered User
    Join Date
    08-23-2017
    Location
    HK
    MS-Off Ver
    2013
    Posts
    3

    Specifying an email address and folder name(Not default) if i have more than 1 email addre

    I need all your Excel VBA expert to help.

    The following code is working but I have a few following questions
    1) If I have more than 1 email address in Outlook and would like to specific email address in Excel . Let say in tab, cell (A1 ) in Sheets("Main") is for me to type email address(group email address). How can I specific it in the following code

    2) If I have to specific a folder (not default folder--inbox,sent,draft, delete) and would like to specific in folder name in Excel Let say in , cell (B1) in Sheets ("Main") is for me to type folder name. How can I specific it in the following code
    =====================================================
    Sub GetFromInbox()
    
        Dim olApp As Outlook.Application
        Dim olNs As Namespace
        Dim Fldr As MAPIFolder
        Dim olMail As Variant
        Dim i, ij As Integer
        Dim tt As Date
    
        Set olApp = New Outlook.Application
        Set olNs = olApp.GetNamespace("MAPI")
        Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
        i = 1
        ij = 0
        x = Date
    
        ' Now. the following "For each next " code starts to look in the oldest email!
       
    
    
        For Each olMail In Fldr.Items
            ij = ij + 1
            'If IsNumeric((Format(olMail.ReceivedTime, "dd/mm/yy"))) Then
                Sheets("test").Range("a1").Select
                Sheets("test").Range("I1").Clear
                Sheets("test").Range("I2") = ij
                Sheets("test").Range("I1").Value = (Format(olMail.ReceivedTime, "dd/mm/yy"))
                Sheets("test").Range("I1").NumberFormat = "dd/mm/yy"
                tt = Sheets("test").Range("I1")
                ' MsgBox ("Y-tt=" & tt & " receivedtime=" & olMail.ReceivedTime)
            'Else
                'tt = 0
                'MsgBox ("N-tt=" & tt & " receivedtime=" & olMail.ReceivedTime)
            'End If
            ' tt = CDate(Format(olMail.ReceivedTime, "dd/mm/yy"))
            If tt >= Range("H1") Then
                'If InStr(olMail.Subject, "others") > 0 And tt >= Range("h1") Then
                If InStr(olMail.Subject, "others") > 0 Then
                    ActiveSheet.Range("h2") = "y"
                    ActiveSheet.Cells(i, 1).Value = olMail.Subject
                    ActiveSheet.Cells(i, 2).Value = olMail.ReceivedTime
                    ActiveSheet.Cells(i, 3).Value = olMail.SenderName
                    tt = CDate(Format(olMail.ReceivedTime, "dd/mm/yy"))
                    ActiveSheet.Cells(i, 4).Value = CDate(Format(olMail.ReceivedTime, "dd/mm/yy"))
                    ' tt = ActiveSheet.Cells(i, 4).Value
                    ActiveSheet.Cells(i, 5).Value = (Format(olMail.ReceivedTime, "hh:mm"))
                    MsgBox ("tt=" & tt)
                    i = i + 1
                End If
            Else
                Sheets("test").Range("h2") = "N"
            End If
        Next olMail
    
        Set Fldr = Nothing
        Set olNs = Nothing
        Set olApp = Nothing
        'tt = ""
    
    End Sub
    Last edited by Pepe Le Mokko; 02-20-2020 at 09:13 AM. Reason: Add code tags

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,605

    Re: Specifying an email address and folder name(Not default) if i have more than 1 email a

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    I did it for you this time. Please read forum rules. Thanks

+ 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] Changing the email address to NOT be the default.
    By sungen99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-23-2019, 08:20 PM
  2. 1 email per email address, include cell value in email subject
    By melody10 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-31-2019, 10:27 PM
  3. Replies: 3
    Last Post: 03-11-2019, 05:31 PM
  4. [SOLVED] vba email send from excel - ignore second email address if "ENTER EMAIL ADDRESS"
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2016, 07:22 AM
  5. Send an email via outlook from and address other than your default email.
    By sungen99 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-28-2015, 06:15 PM
  6. Replies: 1
    Last Post: 03-08-2012, 01:57 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