rollingzep
Board Regular
- Joined
- Nov 18, 2013
- Messages
- 224
- Office Version
- 365
- Platform
- Windows
Hi,
I have a command click event which imports all Outlook attachments into a shared folder and works fine.
But I need to schedule this as a job on a Task Scheduler to Import before Users log before 9.00 am.
I think an autoexec macro is needed for the Task Scheduler to trigger the import. I am not sure.
How to convert my command click event code into a macro?
I know that the code is to be as a function to be run from a macro.
But not sure how to convert the click event code as a function.
TIA
I have a command click event which imports all Outlook attachments into a shared folder and works fine.
But I need to schedule this as a job on a Task Scheduler to Import before Users log before 9.00 am.
I think an autoexec macro is needed for the Task Scheduler to trigger the import. I am not sure.
How to convert my command click event code into a macro?
I know that the code is to be as a function to be run from a macro.
But not sure how to convert the click event code as a function.
VBA Code:
Private Sub cmdOutlook_Click()
Dim olApp As Object
Dim MYFOLDER As Object
Dim OlItems As Object
Dim OlMail As Object
Dim x As Integer
Dim strFile As String
Dim strFolderpath As String
Set olApp = GetObject(, "Outlook.Application")
If Err.Number = 429 Then
Set olApp = CreateObject("Outlook.Application")
End If
strFolderpath = "C:\Users\pg\Testing"
'On Error Resume Next
' Set the Attachment folder.
strFolderpath = strFolderpath & "\Attachments\"
Set MYFOLDER = olApp.GetNamespace("MAPI").Folders("WeeklyProceedings Mailbox").Folders("Inbox")
Set OlItems = MYFOLDER.Items
For Each OlMail In OlItems
strFile = OlMail & ".XML"
strFile = strFolderpath & strFile
If OlMail.Attachments.Count > 0 Then
For x = 1 To OlMail.Attachments.Count
OlMail.Attachments.item(x).SaveAsFile strFile
Next x
End If
Next
Set MYFOLDER = Nothing
Set OlMail = Nothing
Set OlItems = Nothing
Set olApp = Nothing
End Sub
TIA
Last edited: