Run-time error '-2147467259 (80004005)'

L

Lynn

hi,
i have got a pop-up error message "Run-time error '-2147467259
(80004005)'
The operation failed. when i run this macro in outlook. pls help.
thanks

Sub SaveItems()


Dim objItem As Object
Dim objSelection As Selection
Dim strPath As String
Dim strFile As String
Dim intCounter As Integer


'Retrieve a reference to the selected items in the active folder
Set objSelection = Application.ActiveExplorer.Selection


If objSelection.Count = 0 Then
MsgBox "You must select at least one item to save first.",
vbCritical,
"No Items Selected"
Else
'Initialize variables
strPath = "c:"
intCounter = 0
'Cycle through all items in the selection
For Each objItem In objSelection
'Increment the counter
intCounter = intCounter + 1
'Create the filename
strFile = strPath & Format$(intCounter, "000") & " - " &
objItem.Subject & ".msg"
'Save the item
objItem.SaveAs strFile, olMSG
Next


Set objItem = Nothing


MsgBox intCounter & " items were saved to " & strPath


End If


Set objSelection = Nothing


End Sub
 
M

Michael Bauer

Hi Lynn,

strPath needs to end up with an backslash. In addtion, you can´t know,
whether a mail subject contains characters, which aren´t allowed for
filenames. Therefor you can use this sample:


' Replaces non-allowed filename characters by sChr
Private Sub ReplaceCharsForFileName(sName As String, sChr As String)
sName = Replace(sName, "/", sChr)
sName = Replace(sName, "\", sChr)
sName = Replace(sName, ":", sChr)
sName = Replace(sName, "?", sChr)
sName = Replace(sName, Chr(34), sChr)
sName = Replace(sName, "<", sChr)
sName = Replace(sName, ">", sChr)
sName = Replace(sName, "|", sChr)
End Sub
 
L

Lynn

if c: drive already have a copy of the mail with the same topic. How
can i modify this macro to do this checking ?
 
M

Michael Bauer

Hi Lynn,

VBA knows the Dir function for this job. I´ve read that this function
doesn´t work correctly in every situation but can´t remember on details.
I´m using the following code without any problems:


Private Declare Function SHPathFileExists Lib "shell32" _
Alias "#45" (ByVal szPath As String) As Long

' Author :Harald M. Genauck
Public Function PathFileExists(sFilePath As String) As Boolean
If Len(Environ$("OS")) Then
' NT-Systems
PathFileExists = CBool(SHPathFileExists(StrConv(LTrim$(sFilePath), _
vbUnicode)))
Else
' Win 9x
PathFileExists = CBool(SHPathFileExists(LTrim$(sFilePath)))
End If
End Function
 

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