I have the following Outlook VBA that runs when an email comes in that will open a csv file in Excel, copy the data in it (excluding the header row), open an Access Database, open a table, delete the tables rows and paste the new data in and close both Access and Excel when complete.
I have this code running on several rules and keep getting a 91 error code.
Code below:
Public Sub CopyPasteIAFeed(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim ExApp As Excel.Application
Dim ExWbk As Workbook
On Error GoTo CopyPasteIAFeed_Error
Set ExApp = CreateObject("Excel.Application")
Set ExWbk = ExApp.Workbooks.Open("C:\Users\" & Environ("UserName") & "\Documents\NCR\Data Feeds\Report NCR - Daily New Activity Requests.csv")
' Open Feed in Microsoft Excel window.
ExApp.Visible = True
ExApp.ScreenUpdating = True
ExApp.ActiveSheet.Range("A2").Select
ExApp.ActiveSheet.Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
Dim oApp As Access.Application
Dim LPath As String
LPath = "C:\Users\" & Environ("UserName") & "\Documents\NCR\Database\SP - Link to KM - Non-Critical Request Repository.accdb"
Set oApp = CreateObject("Access.Application")
' Open database in Microsoft Access window.
oApp.OpenCurrentDatabase LPath
oApp.Visible = True
oApp.DoCmd.OpenTable "ReportNCRDailyNewActivity", acViewNormal, acEdit
oApp.DoCmd.RunSQL "DELETE * FROM ReportNCRDailyNewActivity"
oApp.DoCmd.RunCommand acCmdPasteAppend
oApp.CloseCurrentDatabase
oApp.Quit acQuitSaveAll
ExApp.CutCopyMode = False
ExApp.Quit
Set objAtt = Nothing
Set oApp = Nothing
Set ExApp = Nothing
MsgBox "InStream Activity Feed Imported. Continue"
On Error GoTo 0
Exit Sub
CopyPasteIAFeed_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure CopyPasteIAFeed of Module Module10"
End Sub