Nelson78
Well-known Member
- Joined
- Sep 11, 2017
- Messages
- 526
- Office Version
- 2007
Hello everybody.
I'm building an automatic process in Microsoft Outlook in "thisoutlooksession" module.
Now, I need Microsoft Outlook to open an Excel workbook located in a specific folder.
I've developped a code that works fine if triggered in Excel with a regular macro.
How can I instruct Microsoft Outlook to perform the same task?
I'm building an automatic process in Microsoft Outlook in "thisoutlooksession" module.
Now, I need Microsoft Outlook to open an Excel workbook located in a specific folder.
I've developped a code that works fine if triggered in Excel with a regular macro.
How can I instruct Microsoft Outlook to perform the same task?
Code:
Sub LoopThroughFiles()
Dim MyObj As Object, MySource As Object, File As Object
Dim MyFile As String
Set MyObj = CreateObject("Scripting.FileSystemObject")
Set MySource = MyObj.GetFolder("C:\Users\xxxx.yyyy\Desktop\zzzzzzzzzz\")
Dim count As Integer
count = 0
For Each File In MySource.Files
count = count + 1
Next File
If count = 1 Then Workbooks.Open ("C:\Users\xxxx.yyyy\Desktop\zzzzzzzzzz\report.xlsm")
If count > 1 Then
For Each File In MySource.Files
MyFile = File
If File Like "*_*" Then
Workbooks.Open (MyFile)
End If
Next File
End If
End Sub