.Lookin through Outlook

A

Andy

Hi all,

I have some code that copies csv files from folder to folder but I
need to modify it to move the files from an Outlook folder to a normal
folder. I'm not experienced at all with any Outlook code in Excel so
any help would be appreciated!

Below is the part of code I'm having problems with.
I used some other code to get it started but my main issue is that
the .Lookin seems to keep defaulting to the users personal folder
instead of the path I give it.

Spath at the moment is the Outlook folder and SDestpath is the normal
folder I want the files moved to.
I just can't get the code to reset the .lookin and use the Spath
instead!

Function iWorkbooksPosted() As Integer

Dim olApp As Outlook.Application, olFolder As Outlook.MAPIFolder,
_
olDocumentItem As Outlook.DocumentItem, olMailItem As
Outlook.MailItem, _
olAtt As Outlook.Attachment

Dim wdDoc As Word.Document, wdRng As Word.Range

Dim wbk As Workbook, wks As Worksheet, wksSource As Worksheet
Dim c As Range, Rng As Range
Dim sDestPath As String, strMailBody As String, sRegionID As
String, _
fn As String, sDataType As String, sFile As String, sPath As
String, _
sCSVFile As String, tempstr As String
Dim counter As Integer, vFileNum As Integer
Dim i As Long, j As Long, lRCount As Long, lDupes As Long, x As
Long
Dim bProcSuccess As Boolean

sDestPath = Worksheets("Main").Range("E1")
sPath = Worksheets("Main").Range("E2")

On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err.Number = 429 Then
Err.Clear
Set olApp = New Outlook.Application
End If

On Error GoTo ErrorHandler

With Application.FileSearch

.NewSearch
.LookIn = sPath
.FileType = msoFileTypeExcelWorkbooks
.Filename = "*.csv"
If .Execute > 0 Then ' found workbooks in Temporary EOSR
folder
For x = 1 To .FoundFiles.Count
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top