Hello,

I am new to VBA and I'm having a hard time finding out what the issue is with my code. Everything seemed to be working fine, but now I figured out that when I'm want to export a folder from Outlook with 16 emails in it, Excel is only pulling in 15. It seems to be skipping one line of data. I've tried messing with the code and I got a "Method 'Rows' of object '_Worksheet' failed" message with this part of the code being highlighted:

rCount = wks.Range("A1:C1" & wks.Rows.Count, 1).End(-4162).Row

I have posted the complete code below. Thank you for any help, it will be much appreciated.

Option Explicit
Sub CopyToExcel()
Dim rCount As Long
Dim strPath As String
Dim strSheet As String
Dim objOL As Outlook.Application
Dim objFolder As Outlook.MAPIFolder
Dim objItems As Outlook.Items
Dim obj As Object
Dim olItem 'As Outlook.MailItem
Dim strColA, strColB, strColC As String
Dim nms As Outlook.NameSpace
Dim appExcel As Excel.Application
Dim wkb As Excel.Workbook
Dim wks As Excel.Worksheet
strSheet = "OutlookCounterTemplate.xlsm"
strPath = "C:\Users\Documents\"
strSheet = strPath & strSheet
Debug.Print strSheet
Set nms = Application.GetNamespace("MAPI")
Set objFolder = nms.PickFolder


Set appExcel = CreateObject("Excel.Application")
appExcel.Workbooks.Open (strSheet)
Set wkb = appExcel.ActiveWorkbook
Set wks = wkb.Sheets(1)
wks.Activate
appExcel.Application.Visible = True


Dim rng As Range
Set rng = wks.Range("A1:C1")
With rng
.Font.Bold = True
.Font.Underline = True
.Font.Size = 12
.Select
End With


If wks.Range("A1") = "" Then
wks.Range("A1") = "Sender Name"
wks.Range("B1") = "To"
wks.Range("C1") = "Modified"
End If


On Error Resume Next
rCount = wks.Range("A1:C1" & wks.Rows.Count).End(-4162).Row


Set objOL = Outlook.Application
Set objFolder = objOL.PickFolder.Selection
Set objItems = objFolder.Items
For Each obj In objItems
Set olItem = obj


strColA = olItem.SenderName
strColB = olItem.To
strColC = olItem.LastModificationTime


wks.Range("A" & rCount).Offset(1) = strColA
wks.Range("B" & rCount).Offset(1) = strColB
wks.Range("C" & rCount).Offset(1) = strColC


rCount = rCount + 1

Next

wks.Rows.WrapText = False

End Sub