bnfkru4567
New Member
- Joined
- Aug 20, 2017
- Messages
- 10
Hi everyone
I need your expert help !!
Please refer to the code below. The code will be in Excel VBA (I am using Excel and outlook 2013 version) and then run it in order to extract a large amount of email in outlook
I have 3 questions and need your help
I need your expert help !!
Please refer to the code below. The code will be in Excel VBA (I am using Excel and outlook 2013 version) and then run it in order to extract a large amount of email in outlook
I have 3 questions and need your help
- Let's say my "Inbox" has around 400+ emails and while I was running the following code, the error 438 came out when the code was searching up to 23 email. How can I solve it out?
- Please refer to the code below:
<code>Dim olMail As Variant <-----------------</code>Should I use "object" or "variant"? Which is better and why? - In the near future, my Outlook will have more than 1 email account. Let's say
the first email account is <code>abc@def.com</code> and
the second email account is <code>abcd1@abc.com</code>.
In future, I will sometimes need to run the code for the first email account and sometimes for second email account.
How can I switch them?
--------------------------------------------------------------
<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") <questions 2---how="" can="" i="" change="" it="" in="" here="" to="" add="" more="" 1="" email="" address?????=""></questions></code>
<code></code>
<code></code> <code>
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
i = 1
ij = 0</code>
<code>x = Date
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")) <---<code>Question 1 : while ij was counting up to 23, the error 438 stopped in here?? I have no idea why !! ---></code>
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 <------------H1 is a date and let say 15/01/17
'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</code>