Hi Lynn,
I think here are some misunderstandings. Please let´s try again
You´ve asked what the code, you was pointed to, is doing.
1) Well, it first expects, that there is an Inspector opened. E.g. if
you double click on an MailItem, then the item will be opened. The
window, this item is shown in, is called Inspector. The active window is
called ActiveInspector. That is, if there is no MailItem, ContactItem
(or whatever) window opened, there is also no ActiveInspector object.
This is *probably* the reason for the Error 91 in your scenario.
2) Then a file name is created from the current (shown) MailItem´s
ReceivedTime and Subject properties. Ok, there are some french words,
but that´s absolutely ok. You´re free, using the Ork´s language, if you
like doing so
The filename string could contain any, for a filename unallowed,
character. This case will be handled by all the Replace function calls.
3) Next step: The code uses an Excel mechanism, which lets you define
where a file should be saved. Unfortunately a similar one isn´t
available in Outlook.
4) And now I have to guess a little bit. Once uppon the time my teacher
told me about my terrible french - and she was right
I think, the user will be notified, if there is a same named file
existing already and (s)he has to decide, what has to be done.
The ShellExecute call opens the existing file, SetForeGroundWindow
brings it´s window on top.
I hope, this little explanations will be helpful for you.
--
Viele Grüße
Michael Bauer
hi guys,
i used the code as found in
http://www.outlookcode.com/codedetail.aspx?id=629
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As
Long) As Long
Public Declare Function ShellExecute _
Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Sub move_to_archive()
Dim Nom_Mail, Annee, Mois, Jour As String
Dim Reponse As Integer
Dim fs
Dim ProcID As Long
Chrono_Mail = ""
Set myOlApp = CreateObject("Outlook.Application")
Set myXlApp = CreateObject("Excel.Application")
Set fs = CreateObject("Scripting.FileSystemObject")
Chemin = "C:\"
myXlApp.DefaultFilePath = Chemin
Set Mail_Courant = myOlApp.ActiveInspector.CurrentItem
MsgBox myOlApp.ActiveInspector.Name
Chrono_Mail = Mail_Courant.ReceivedTime
Nom_Mail = Replace(Chrono_Mail, "/", "")
Annee = Mid(Nom_Mail, 7, 2)
Mois = Mid(Nom_Mail, 3, 2)
Jour = Mid(Nom_Mail, 1, 2)
Nom_Mail = "Email_" & Annee & Mois & Jour & "_" & Mail_Courant.Subject
Nom_Mail = Replace(Nom_Mail, ":", "")
Nom_Mail = Replace(Nom_Mail, "/", " ")
Nom_Mail = Replace(Nom_Mail, "\", " ")
Nom_Mail = Replace(Nom_Mail, "?", " ")
Nom_Mail = Replace(Nom_Mail, "*", " ")
Nom_Mail = Replace(Nom_Mail, "<", " ")
Nom_Mail = Replace(Nom_Mail, ">", " ")
Nom_Mail = Replace(Nom_Mail, ".", " ")
Nom_Mail = Replace(Nom_Mail, Chr(34), " ")
myXlApp.DefaultFilePath = Chemin
fileSaveName = myXlApp.GetSaveAsFilename(Nom_Mail, _
fileFilter:="Message Format (*.msg), *.msg", Title:="Archivage Mail")
fileSaveName_Replace = fileSaveName
myXlApp.Quit
Set myXlApp = Nothing
If fileSaveName = "False" Then Exit Sub
If Len(fileSaveName) > 2 Then
If fs.FileExists(fileSaveName) Then
Reponse = MsgBox("Un fichier du même nom exite déjà !" &
Chr(13) _
& "Voulez-vous le remplacer ?" & Chr(13) & "Cliquez No pour
l'ouvrir", vbYesNoCancel, "Remplacer fichier")
Select Case Reponse
Case 6
Mail_Courant.SaveAs fileSaveName_Replace, olMSG
Mail_Courant.Close 1
Case 7
On Error Resume Next
ProcID = ShellExecute(hwnd, "open", fileSaveName,
vbNullString, "C:\", 1)
SetForegroundWindow (ProcID)
Set myOlApp = CreateObject("Outlook.Application")
Set Mail_Archive = myOlApp.ActiveInspector.CurrentItem
Chrono_Archive = Mail_Archive.ReceivedTime
Case Else: Exit Sub
End Select
Else: Mail_Courant.SaveAs fileSaveName, olMSG
End If
End If
End Sub
any idea?