rdy123 rdy
asked on
vba code in excel to save the current open mail item as .msg or .oft file in a location
i have a opened outlook mail, i want to save that opened current mail to location C:\temp as .msg or .oft,is there any code to save the current mail as .msg format and i also want to replace the .msg file always with the new mail and save it with the same .msg file name.
please suggest
please suggest
ASKER
hi,
thank you for your response,but i am getting runtime error 70, any suggestions please
thank you for your response,but i am getting runtime error 70, any suggestions please
ASKER
i have tried giving location in my documents its working fine but it is not saving the current opened mail,its saving the first mail in outlook
ASKER
Hi,
i used the below code,but it is opening new mail and saving it in the specified location,but i want to run the code on opened current mail,please suggest which line to be changed to save the current mail
Sub msg()
Const olMailItem = 0
Const olMSG = 3
Dim olkApp, olkMsg
Dim myItem As Outlook.MailItem
'Set olkApp = CreateObject("Outlook.Appl ication")
Set olkApp = GetObject(, "Outlook.Application")
'Set myItem = olkApp.ActiveInspector.Cur rentItem
olkApp.Session.Logon "Outlook"
Set olkMsg = olkApp.CreateItem(olMailIt em)
Set myItem = olkApp.ActiveInspector.Cur rentItem
With olkMsg
.Subject = "Some Subject"
.Body = "Some text"
.SaveAs "C:\untitle.msg", olMSG
End With
Set olkMsg = Nothing
Set olkApp = Nothing
End Sub
i used the below code,but it is opening new mail and saving it in the specified location,but i want to run the code on opened current mail,please suggest which line to be changed to save the current mail
Sub msg()
Const olMailItem = 0
Const olMSG = 3
Dim olkApp, olkMsg
Dim myItem As Outlook.MailItem
'Set olkApp = CreateObject("Outlook.Appl
Set olkApp = GetObject(, "Outlook.Application")
'Set myItem = olkApp.ActiveInspector.Cur
olkApp.Session.Logon "Outlook"
Set olkMsg = olkApp.CreateItem(olMailIt
Set myItem = olkApp.ActiveInspector.Cur
With olkMsg
.Subject = "Some Subject"
.Body = "Some text"
.SaveAs "C:\untitle.msg", olMSG
End With
Set olkMsg = Nothing
Set olkApp = Nothing
End Sub
Runtime error 70 means that you don't have permission to write to that directory.
Line 7 of my original code should read:
Line 7 of my original code should read:
oMail.SaveAs "C:\temp\" & "name_of_message" & ".msg", olMSG
ASKER
i have tried the same,and by giving other folder it worked,but the issue is, it is saving the first mail of inbox instead of saving the current opened mail.
It should be saving the selected message, is that not the case?
ASKER
no,it should save the current mail which is already opened,please advise.
Try this:
Public Sub SaveMessageAsMsg()
Dim myItem As Outlook.Inspector
Dim objItem As Object
Set myItem = Application.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
oMail.SaveAs "C:\temp\" & "name_of_message" & ".msg", olMSG
Else
MsgBox "There is no current active inspector."
End If
End Sub
ASKER
hi, thank you,i have tried the above code but i am getting run time error 438.please advise.
Oops, my bad, here this should work:
Public Sub SaveMessageAsMsg()
Dim myItem As Outlook.Inspector
Dim objItem As Object
Set myItem = Application.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
objItem.SaveAs "C:\temp\" & "name_of_message" & ".msg", olMSG
Else
MsgBox "There is no current active inspector."
End If
End Sub
ASKER
thank you for quick response,but its the same and giving the same error.
On which line does the error occur?
ASKER
Set myItem = Application.ActiveInspecto r
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
wow,that's perfect -Subodh Tiwari (Neeraj),thank you both again
You're welcome. Glad it worked for you.
Also I think you should have split the points considering the assistance offered by MacroShadow. If you agree, please click the Request Attention button and raise a request to open the question so that you can split the points by accepting the answers again. :)
Also I think you should have split the points considering the assistance offered by MacroShadow. If you agree, please click the Request Attention button and raise a request to open the question so that you can split the points by accepting the answers again. :)
ASKER
yup,i thought the same to split the points instead of cancel i have clicked submit,again i am unable to change,can i know how to share points again,and where is Request Attention button?
No problem.
As I said you may use Request Attention link in this case.
In your first post with question itself, you will find the three dots next to the share icon and if you click the three dots, you will find a link to Request Attention. Click it and request to reopen the question explaining the issue and a moderator will take care of this.
As I said you may use Request Attention link in this case.
In your first post with question itself, you will find the three dots next to the share icon and if you click the three dots, you will find a link to Request Attention. Click it and request to reopen the question explaining the issue and a moderator will take care of this.
ASKER
thanks a lot..
Thanks for splitting the points. :)
Glad we could help.
Glad we could help.
Open in new window