Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to locate a new outlook folder

Hi There

I am quite inexperienced using VBA but have managed to put the
following piece of code together that nearly does exactly what I need.

Basically when I receive an email with a certain subject heading
outlook opens a spreadsheet which auto runs this macro to search my
inbox for emails with taht subject heading and processes the
attachment.

My only problem is that I dont want it to search my Inbox I want it to
search my sub folder Inbox1. I know this may seem a simple request but
I have tried and I have no idea how to do it.

Any help would be greatfully appreciated.

Thanks in advance

Jamie

Code:


Sub auto_open()

Windows("EIS Job Log test.xls").Activate
Range("B2").Select



Dim olApp As Outlook.Application
Dim olNs As NameSpace
Dim Fldr As MAPIFolder
Dim MoveToFldr As MAPIFolder
Dim olMi As MailItem
Dim olAtt As Attachment
Dim MyPath As String
Dim i As Long

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set MoveToFldr = Fldr.Folders("eisreq")
MyPath = "I:\EIS\Forms\EIS Requests\"
dattim = Format(Date, "yyyymmdd") & " " & "Time-" & Format(Time,
"hhmmss")


For i = Fldr.Items.Count To 1 Step -1
Range("A1").Select


rowlength = Selection.CurrentRegion.Rows.Count
Set olMi = Fldr.Items(i)
If InStr(1, olMi.Subject, "EIS_REQUEST") 0 Then
For Each olAtt In olMi.Attachments
If olAtt.Filename = "EIS Request.xls" Then
olAtt.SaveAsFile MyPath & Fldr.Items.Count & " " &
olMi.SenderName & " " & "Date-" & dattim & ".xls"
open1 = MyPath & Fldr.Items.Count & " " &
olMi.SenderName & " " & "Date-" & dattim & ".xls"
filenm = Fldr.Items.Count & " " & olMi.SenderName &
" " & "Date-" & dattim & ".xls"
End If

Next olAtt
olMi.save
olMi.Move MoveToFldr
Workbooks.Open Filename:=open1

'copies and pastes data from eis request
Range("IR4:IV4").Select
Selection.Copy
Windows("EIS Job Log test.xls").Activate
Range("A1").Select
For x = 1 To rowlength
If ActiveCell.Cells < "" Then
Cells(ActiveCell.Row + 1, 1).Select
End If
Next x
Selection.PasteSpecial paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False

'copies and pastes filename
Range("E1").Select
For x = 1 To rowlength
If ActiveCell.Cells < "" Then
Cells(ActiveCell.Row + 1, 6).Select
End If
Next x
ActiveCell = filenm

Windows(filenm).Activate
ActiveWorkbook.Close False

Windows("EIS Job Log test.xls").Activate
ActiveWorkbook.save

End If
Next i
ActiveWorkbook.Close False
Set olAtt = Nothing
Set olMi = Nothing
Set Fldr = Nothing
Set MoveToFldr = Nothing
Set olNs = Nothing
Set olApp = Nothing

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
From Outlook to Excel Personal Folder Roy Hobbs Excel Worksheet Functions 0 October 10th 10 04:33 AM
Outlook attachment to network folder Ozzie via OfficeKB.com Excel Discussion (Misc queries) 2 February 3rd 06 11:19 AM
Outlook Automation Error Problem - Can't locate Outlook Module Allan P. London[_2_] Excel Programming 1 August 14th 05 10:52 PM
How do I locate the Exploring PowerPoint folder in Word & Excel? Best271974 Excel Discussion (Misc queries) 1 May 22nd 05 09:52 PM
How do I link to an Outlook public folder from an Excel spreadshe. DJBaker Excel Discussion (Misc queries) 0 January 28th 05 07:35 PM


All times are GMT +1. The time now is 06:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"