?
Solved

How to reference a file folder with a variable extension?

Posted on 2004-08-30
12
Medium Priority
?
225 Views
Last Modified: 2008-03-17
I have the following function in a program which creates a new directory(folder) for the current day. This program runs once a day. So everyday it would create a new folder. Example:

s:\temp\MSR\30-Aug-04
s:\temp\MSR\31-Aug-04
s:\temp\MSR\01-Sep-04
and so on....

Function Make_Folder()
 Dim Folder As String
 Folder = "s:\temp\MSR\" & Format(Now, "d-mmmm-yy")
 If Dir(Folder, vbDirectory) = "" Then
    MkDir Folder
 End If
End Function

Then I have the following '.exe' which gets triggered by a rule in Outlook to look in the 'InBox' folder for certain type of messages based on the 'Subject' text that I want stored in the current day folder based on it being created by the above.
I'm not sure how to assign a variable to the following statement below:

oMessage.SaveAs "s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy") & "Incident Alert.msg", olMSG

The way I have it now it's adding the: Format(Now, "d-mmmm-yy") to the .msg. So it ends up looking like this:

30-Aug-04Incident Alert.msg

I want the message to go into the current day folder. And then the next day the .msg's would go to another new folder that was created.


Private Sub Main()
Dim oOutlook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim oMessage As Outlook.MailItem
Set oOutlook = New Outlook.Application
Set oNs = oOutlook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFolderInbox)


For Each oMessage In oFldr.Items
    If InStr(1, oMessage.Subject, "Incident Alert") > 0 Then
    oMessage.SaveAs "s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy") & "Incident Alert.msg", olMSG
    oMessage.Delete
End If

    Next oMessage
 
    Set oMessage = Nothing
    Set oFldr = Nothing
    Set oNs = Nothing
    Set oOutlook = Nothing
   
End Sub

Any Ideas??
0
Comment
Question by:Richard Kreidl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
12 Comments
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11932032
oMessage.SaveAs "s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy") & "\Incident Alert.msg", olMSG
0
 
LVL 2

Expert Comment

by:x50Fade
ID: 11932189
Yup...you just forgot your slash before your filename....as mladenovicz pointed out
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 11932320
I get an internal application error when I added the slash.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:x50Fade
ID: 11932355
Are you sure that s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy") exists...have you allready created it?
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11932362
Private Sub Main()
Dim oOutlook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim oMessage As Outlook.MailItem
Dim FileName As String

Set oOutlook = New Outlook.Application
Set oNs = oOutlook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFolderInbox)


For Each oMessage In oFldr.Items
    If InStr(1, oMessage.Subject, "Incident Alert") > 0 Then
    FileName = "s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy") & "Incident Alert.msg"
    Debug.Print FileName
    oMessage.SaveAs FileName, olMSG
    oMessage.Delete
End If

    Next oMessage
 
    Set oMessage = Nothing
    Set oFldr = Nothing
    Set oNs = Nothing
    Set oOutlook = Nothing
   
End Sub

Can you post content of immediate window here?
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11932386
Function Make_Folder()
 Dim Folder As String
 Folder = "s:\temp\MSR\" & Format(Now, "d-mmmm-yy")
 If Dir(Folder, vbDirectory) = "" Then
    MkDir Folder
 End If
End Function

Shouldn't this

 Folder = "s:\temp\MSR\" & Format(Now, "d-mmmm-yy")

be

 Folder = "s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy")
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 11932406
Here it is:

s:\temp\MSR\Incident Alert\30-August-04Incident Alert.msg
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 11932443
Here it is with a slash before the file name:

s:\temp\MSR\Incident Alert\30-August-04\Incident Alert.msg
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11932459
Does folder s:\temp\MSR\Incident Alert\30-August-04 exists?
0
 
LVL 8

Accepted Solution

by:
mladenovicz earned 1000 total points
ID: 11932472
if it does not exist then

For Each oMessage In oFldr.Items
    If InStr(1, oMessage.Subject, "Incident Alert") > 0 Then
    Call Make_Folder
    oMessage.SaveAs "s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy") & "Incident Alert.msg", olMSG
    oMessage.Delete
End If
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 11932565
I'm still getting an internal application error. Here is the code I'm testing with:
Private Sub Main()
Dim oOutlook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim oMessage As Outlook.MailItem
Dim FileName As String

Set oOutlook = New Outlook.Application
Set oNs = oOutlook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFolderInbox)

For Each oMessage In oFldr.Items
    If InStr(1, oMessage.Subject, "Incident Alert") > 0 Then
    Call Make_Folder
    oMessage.SaveAs "s:\temp\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy") & "\Incident Alert.msg", olMSG
    oMessage.Delete
End If


    Next oMessage
 
    Set oMessage = Nothing
    Set oFldr = Nothing
    Set oNs = Nothing
    Set oOutlook = Nothing
   
End Sub

Function Make_Folder()
 Dim Folder As String
 Folder = "s:\group0k\MSR\Incident Alert\" & Format(Now, "d-mmmm-yy")
 If Dir(Folder, vbDirectory) = "" Then
    MkDir Folder
 End If
End Function

0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 11932595
I found the problem I had one of the folders setup wrong. Thanks for all the help
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question