Error occuring regarding Mismatch of Type












1














I am putting together a VBA macro for Outlook and I am getting a "Run-time error '13': Type mismatch. I am not that experienced with VBA so I could really use some help. The program is to import subject from inbox mails of outlook, it was working fine but now Runtime error '13' on line "Next olItem".



Sub PullOutlookData()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False

Dim olApp As Outlook.Application, olNs As Outlook.Namespace
Dim olItems As Outlook.Items
Dim olItem As Outlook.MailItem
Dim ws As Worksheet
Dim lRow As Long
Dim vItem
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")

Set ws = ThisWorkbook.Sheets("OutlookRecord") '<--- relevant worksheet name
Set olItems = olNs.Folders("faizan.farooq@ke.com.pk").Folders("Inbox").Items '<--- RELEVANT FOLDER name
rCount = 1
Sheet14.Range("A1:D2000").Clear
For Each olItem In olItems
rCount = rCount + 1
ws.Range("A" & rCount).value = olItem.SenderName
ws.Range("B" & rCount).value = olItem.Subject

Next olItem
ws.UsedRange.WrapText = False

Call SliceDice
Call FlipColumns

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True

End Sub
Private Sub test()
Application.OnTime Now + TimeValue("00:01:00"), "PullOutlookData"
End Sub









share|improve this question
























  • On which line are you getting this error ?
    – Imran Malek
    Nov 23 '18 at 6:00










  • Next olItem ....
    – M Faizan Farooq
    Nov 23 '18 at 6:08










  • Try Dim olItem As Variant
    – omegastripes
    Nov 23 '18 at 7:14










  • Object doesn't support this property or method error occurring in line { ws.Range("A" & rCount).value = olItem.SenderName}
    – M Faizan Farooq
    Nov 23 '18 at 9:43








  • 1




    Possible duplicate of type mismatch error on loop in vba
    – niton
    Nov 23 '18 at 14:15
















1














I am putting together a VBA macro for Outlook and I am getting a "Run-time error '13': Type mismatch. I am not that experienced with VBA so I could really use some help. The program is to import subject from inbox mails of outlook, it was working fine but now Runtime error '13' on line "Next olItem".



Sub PullOutlookData()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False

Dim olApp As Outlook.Application, olNs As Outlook.Namespace
Dim olItems As Outlook.Items
Dim olItem As Outlook.MailItem
Dim ws As Worksheet
Dim lRow As Long
Dim vItem
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")

Set ws = ThisWorkbook.Sheets("OutlookRecord") '<--- relevant worksheet name
Set olItems = olNs.Folders("faizan.farooq@ke.com.pk").Folders("Inbox").Items '<--- RELEVANT FOLDER name
rCount = 1
Sheet14.Range("A1:D2000").Clear
For Each olItem In olItems
rCount = rCount + 1
ws.Range("A" & rCount).value = olItem.SenderName
ws.Range("B" & rCount).value = olItem.Subject

Next olItem
ws.UsedRange.WrapText = False

Call SliceDice
Call FlipColumns

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True

End Sub
Private Sub test()
Application.OnTime Now + TimeValue("00:01:00"), "PullOutlookData"
End Sub









share|improve this question
























  • On which line are you getting this error ?
    – Imran Malek
    Nov 23 '18 at 6:00










  • Next olItem ....
    – M Faizan Farooq
    Nov 23 '18 at 6:08










  • Try Dim olItem As Variant
    – omegastripes
    Nov 23 '18 at 7:14










  • Object doesn't support this property or method error occurring in line { ws.Range("A" & rCount).value = olItem.SenderName}
    – M Faizan Farooq
    Nov 23 '18 at 9:43








  • 1




    Possible duplicate of type mismatch error on loop in vba
    – niton
    Nov 23 '18 at 14:15














1












1








1







I am putting together a VBA macro for Outlook and I am getting a "Run-time error '13': Type mismatch. I am not that experienced with VBA so I could really use some help. The program is to import subject from inbox mails of outlook, it was working fine but now Runtime error '13' on line "Next olItem".



Sub PullOutlookData()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False

Dim olApp As Outlook.Application, olNs As Outlook.Namespace
Dim olItems As Outlook.Items
Dim olItem As Outlook.MailItem
Dim ws As Worksheet
Dim lRow As Long
Dim vItem
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")

Set ws = ThisWorkbook.Sheets("OutlookRecord") '<--- relevant worksheet name
Set olItems = olNs.Folders("faizan.farooq@ke.com.pk").Folders("Inbox").Items '<--- RELEVANT FOLDER name
rCount = 1
Sheet14.Range("A1:D2000").Clear
For Each olItem In olItems
rCount = rCount + 1
ws.Range("A" & rCount).value = olItem.SenderName
ws.Range("B" & rCount).value = olItem.Subject

Next olItem
ws.UsedRange.WrapText = False

Call SliceDice
Call FlipColumns

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True

End Sub
Private Sub test()
Application.OnTime Now + TimeValue("00:01:00"), "PullOutlookData"
End Sub









share|improve this question















I am putting together a VBA macro for Outlook and I am getting a "Run-time error '13': Type mismatch. I am not that experienced with VBA so I could really use some help. The program is to import subject from inbox mails of outlook, it was working fine but now Runtime error '13' on line "Next olItem".



Sub PullOutlookData()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False

Dim olApp As Outlook.Application, olNs As Outlook.Namespace
Dim olItems As Outlook.Items
Dim olItem As Outlook.MailItem
Dim ws As Worksheet
Dim lRow As Long
Dim vItem
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")

Set ws = ThisWorkbook.Sheets("OutlookRecord") '<--- relevant worksheet name
Set olItems = olNs.Folders("faizan.farooq@ke.com.pk").Folders("Inbox").Items '<--- RELEVANT FOLDER name
rCount = 1
Sheet14.Range("A1:D2000").Clear
For Each olItem In olItems
rCount = rCount + 1
ws.Range("A" & rCount).value = olItem.SenderName
ws.Range("B" & rCount).value = olItem.Subject

Next olItem
ws.UsedRange.WrapText = False

Call SliceDice
Call FlipColumns

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True

End Sub
Private Sub test()
Application.OnTime Now + TimeValue("00:01:00"), "PullOutlookData"
End Sub






excel vba excel-vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 6:10

























asked Nov 23 '18 at 5:49









M Faizan Farooq

487




487












  • On which line are you getting this error ?
    – Imran Malek
    Nov 23 '18 at 6:00










  • Next olItem ....
    – M Faizan Farooq
    Nov 23 '18 at 6:08










  • Try Dim olItem As Variant
    – omegastripes
    Nov 23 '18 at 7:14










  • Object doesn't support this property or method error occurring in line { ws.Range("A" & rCount).value = olItem.SenderName}
    – M Faizan Farooq
    Nov 23 '18 at 9:43








  • 1




    Possible duplicate of type mismatch error on loop in vba
    – niton
    Nov 23 '18 at 14:15


















  • On which line are you getting this error ?
    – Imran Malek
    Nov 23 '18 at 6:00










  • Next olItem ....
    – M Faizan Farooq
    Nov 23 '18 at 6:08










  • Try Dim olItem As Variant
    – omegastripes
    Nov 23 '18 at 7:14










  • Object doesn't support this property or method error occurring in line { ws.Range("A" & rCount).value = olItem.SenderName}
    – M Faizan Farooq
    Nov 23 '18 at 9:43








  • 1




    Possible duplicate of type mismatch error on loop in vba
    – niton
    Nov 23 '18 at 14:15
















On which line are you getting this error ?
– Imran Malek
Nov 23 '18 at 6:00




On which line are you getting this error ?
– Imran Malek
Nov 23 '18 at 6:00












Next olItem ....
– M Faizan Farooq
Nov 23 '18 at 6:08




Next olItem ....
– M Faizan Farooq
Nov 23 '18 at 6:08












Try Dim olItem As Variant
– omegastripes
Nov 23 '18 at 7:14




Try Dim olItem As Variant
– omegastripes
Nov 23 '18 at 7:14












Object doesn't support this property or method error occurring in line { ws.Range("A" & rCount).value = olItem.SenderName}
– M Faizan Farooq
Nov 23 '18 at 9:43






Object doesn't support this property or method error occurring in line { ws.Range("A" & rCount).value = olItem.SenderName}
– M Faizan Farooq
Nov 23 '18 at 9:43






1




1




Possible duplicate of type mismatch error on loop in vba
– niton
Nov 23 '18 at 14:15




Possible duplicate of type mismatch error on loop in vba
– niton
Nov 23 '18 at 14:15












1 Answer
1






active

oldest

votes


















1














Code cleaned up a bit and hopefully fixed your issue...



Sub PullOutlookData()
On Error GoTo ExitSub
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
.DisplayStatusBar = False
.EnableEvents = False
End With
ActiveSheet.DisplayPageBreaks = False

Dim olApp As Outlook.Application: Set olApp = New Outlook.Application
Dim olNs As Outlook.Namespace: Set olNs = olApp.GetNamespace("MAPI")
Dim Inbox As Outlook.MAPIFolder: Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Dim olItems As Outlook.Items: Set olItems = Inbox.Items

Dim olItem As Outlook.MailItem
Dim ws As Worksheet, vItem As Variant, i As Long, rCount As Long

Set ws = ThisWorkbook.Sheets("OutlookRecord") '<--- relevant worksheet name

ws.UsedRange.ClearContents
'Sheet14.Range("A1:D2000").Clear

rCount = 2
For i = 1 To olItems.Count
Set vItem = Inbox.Items.Item(i)
DoEvents
If vItem.Class = olMail Then
ws.Range("A" & rCount) = vItem.SenderName
ws.Range("B" & rCount) = vItem.Subject
rCount = rCount + 1
End If
'If i > 100 Then Exit For
Next i

ws.UsedRange.WrapText = False

'Call SliceDice
'Call FlipColumns

ExitSub:
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.DisplayStatusBar = True
.EnableEvents = True
End With
ActiveSheet.DisplayPageBreaks = True

End Sub





share|improve this answer























  • stackoverflow.com/questions/13617305/…
    – niton
    Nov 23 '18 at 20:52











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441246%2ferror-occuring-regarding-mismatch-of-type%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Code cleaned up a bit and hopefully fixed your issue...



Sub PullOutlookData()
On Error GoTo ExitSub
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
.DisplayStatusBar = False
.EnableEvents = False
End With
ActiveSheet.DisplayPageBreaks = False

Dim olApp As Outlook.Application: Set olApp = New Outlook.Application
Dim olNs As Outlook.Namespace: Set olNs = olApp.GetNamespace("MAPI")
Dim Inbox As Outlook.MAPIFolder: Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Dim olItems As Outlook.Items: Set olItems = Inbox.Items

Dim olItem As Outlook.MailItem
Dim ws As Worksheet, vItem As Variant, i As Long, rCount As Long

Set ws = ThisWorkbook.Sheets("OutlookRecord") '<--- relevant worksheet name

ws.UsedRange.ClearContents
'Sheet14.Range("A1:D2000").Clear

rCount = 2
For i = 1 To olItems.Count
Set vItem = Inbox.Items.Item(i)
DoEvents
If vItem.Class = olMail Then
ws.Range("A" & rCount) = vItem.SenderName
ws.Range("B" & rCount) = vItem.Subject
rCount = rCount + 1
End If
'If i > 100 Then Exit For
Next i

ws.UsedRange.WrapText = False

'Call SliceDice
'Call FlipColumns

ExitSub:
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.DisplayStatusBar = True
.EnableEvents = True
End With
ActiveSheet.DisplayPageBreaks = True

End Sub





share|improve this answer























  • stackoverflow.com/questions/13617305/…
    – niton
    Nov 23 '18 at 20:52
















1














Code cleaned up a bit and hopefully fixed your issue...



Sub PullOutlookData()
On Error GoTo ExitSub
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
.DisplayStatusBar = False
.EnableEvents = False
End With
ActiveSheet.DisplayPageBreaks = False

Dim olApp As Outlook.Application: Set olApp = New Outlook.Application
Dim olNs As Outlook.Namespace: Set olNs = olApp.GetNamespace("MAPI")
Dim Inbox As Outlook.MAPIFolder: Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Dim olItems As Outlook.Items: Set olItems = Inbox.Items

Dim olItem As Outlook.MailItem
Dim ws As Worksheet, vItem As Variant, i As Long, rCount As Long

Set ws = ThisWorkbook.Sheets("OutlookRecord") '<--- relevant worksheet name

ws.UsedRange.ClearContents
'Sheet14.Range("A1:D2000").Clear

rCount = 2
For i = 1 To olItems.Count
Set vItem = Inbox.Items.Item(i)
DoEvents
If vItem.Class = olMail Then
ws.Range("A" & rCount) = vItem.SenderName
ws.Range("B" & rCount) = vItem.Subject
rCount = rCount + 1
End If
'If i > 100 Then Exit For
Next i

ws.UsedRange.WrapText = False

'Call SliceDice
'Call FlipColumns

ExitSub:
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.DisplayStatusBar = True
.EnableEvents = True
End With
ActiveSheet.DisplayPageBreaks = True

End Sub





share|improve this answer























  • stackoverflow.com/questions/13617305/…
    – niton
    Nov 23 '18 at 20:52














1












1








1






Code cleaned up a bit and hopefully fixed your issue...



Sub PullOutlookData()
On Error GoTo ExitSub
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
.DisplayStatusBar = False
.EnableEvents = False
End With
ActiveSheet.DisplayPageBreaks = False

Dim olApp As Outlook.Application: Set olApp = New Outlook.Application
Dim olNs As Outlook.Namespace: Set olNs = olApp.GetNamespace("MAPI")
Dim Inbox As Outlook.MAPIFolder: Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Dim olItems As Outlook.Items: Set olItems = Inbox.Items

Dim olItem As Outlook.MailItem
Dim ws As Worksheet, vItem As Variant, i As Long, rCount As Long

Set ws = ThisWorkbook.Sheets("OutlookRecord") '<--- relevant worksheet name

ws.UsedRange.ClearContents
'Sheet14.Range("A1:D2000").Clear

rCount = 2
For i = 1 To olItems.Count
Set vItem = Inbox.Items.Item(i)
DoEvents
If vItem.Class = olMail Then
ws.Range("A" & rCount) = vItem.SenderName
ws.Range("B" & rCount) = vItem.Subject
rCount = rCount + 1
End If
'If i > 100 Then Exit For
Next i

ws.UsedRange.WrapText = False

'Call SliceDice
'Call FlipColumns

ExitSub:
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.DisplayStatusBar = True
.EnableEvents = True
End With
ActiveSheet.DisplayPageBreaks = True

End Sub





share|improve this answer














Code cleaned up a bit and hopefully fixed your issue...



Sub PullOutlookData()
On Error GoTo ExitSub
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
.DisplayStatusBar = False
.EnableEvents = False
End With
ActiveSheet.DisplayPageBreaks = False

Dim olApp As Outlook.Application: Set olApp = New Outlook.Application
Dim olNs As Outlook.Namespace: Set olNs = olApp.GetNamespace("MAPI")
Dim Inbox As Outlook.MAPIFolder: Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Dim olItems As Outlook.Items: Set olItems = Inbox.Items

Dim olItem As Outlook.MailItem
Dim ws As Worksheet, vItem As Variant, i As Long, rCount As Long

Set ws = ThisWorkbook.Sheets("OutlookRecord") '<--- relevant worksheet name

ws.UsedRange.ClearContents
'Sheet14.Range("A1:D2000").Clear

rCount = 2
For i = 1 To olItems.Count
Set vItem = Inbox.Items.Item(i)
DoEvents
If vItem.Class = olMail Then
ws.Range("A" & rCount) = vItem.SenderName
ws.Range("B" & rCount) = vItem.Subject
rCount = rCount + 1
End If
'If i > 100 Then Exit For
Next i

ws.UsedRange.WrapText = False

'Call SliceDice
'Call FlipColumns

ExitSub:
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.DisplayStatusBar = True
.EnableEvents = True
End With
ActiveSheet.DisplayPageBreaks = True

End Sub






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 18:32

























answered Nov 23 '18 at 18:12









Tragamor

1,72431024




1,72431024












  • stackoverflow.com/questions/13617305/…
    – niton
    Nov 23 '18 at 20:52


















  • stackoverflow.com/questions/13617305/…
    – niton
    Nov 23 '18 at 20:52
















stackoverflow.com/questions/13617305/…
– niton
Nov 23 '18 at 20:52




stackoverflow.com/questions/13617305/…
– niton
Nov 23 '18 at 20:52


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441246%2ferror-occuring-regarding-mismatch-of-type%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Basket-ball féminin

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

I want to find a topological embedding $f : X rightarrow Y$ and $g: Y rightarrow X$, yet $X$ is not...