Only output the message body to txt fileHow to add excel range as a picture to outlook message bodyOutlook 2010 VBA Task with attachmentsRun time error, but only in the second loopMail details with Entry IdImporting TXT to excel whilst skipping first 7 characters and moving to the next colomn after each fileExcel VBA URLDownloadToFile Error for HTTPSresourceSave and print PDF from a FDF fileVba to Edit Links to Latest File in Directoryvba code to search for a text file in all the folders and sub foldersExtract IP Addresses in Microsoft Outlook using macros
Why, historically, did Gödel think CH was false?
I'm planning on buying a laser printer but concerned about the life cycle of toner in the machine
In Japanese, what’s the difference between “Tonari ni” (となりに) and “Tsugi” (つぎ)? When would you use one over the other?
Approximately how much travel time was saved by the opening of the Suez Canal in 1869?
What's the output of a record cartridge playing an out-of-speed record
How does strength of boric acid solution increase in presence of salicylic acid?
Can I ask the recruiters in my resume to put the reason why I am rejected?
What is the word for reserving something for yourself before others do?
"You are your self first supporter", a more proper way to say it
Fencing style for blades that can attack from a distance
Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)
How does one intimidate enemies without having the capacity for violence?
Did Shadowfax go to Valinor?
What are these boxed doors outside store fronts in New York?
US citizen flying to France today and my passport expires in less than 2 months
The use of multiple foreign keys on same column in SQL Server
Method of fabrication patents, Is it okay to import from abroad?
Why do falling prices hurt debtors?
"to be prejudice towards/against someone" vs "to be prejudiced against/towards someone"
How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?
Replacing matching entries in one column of a file by another column from a different file
How is it possible to have an ability score that is less than 3?
Why can't I see bouncing of a switch on an oscilloscope?
Is it unprofessional to ask if a job posting on GlassDoor is real?
Only output the message body to txt file
How to add excel range as a picture to outlook message bodyOutlook 2010 VBA Task with attachmentsRun time error, but only in the second loopMail details with Entry IdImporting TXT to excel whilst skipping first 7 characters and moving to the next colomn after each fileExcel VBA URLDownloadToFile Error for HTTPSresourceSave and print PDF from a FDF fileVba to Edit Links to Latest File in Directoryvba code to search for a text file in all the folders and sub foldersExtract IP Addresses in Microsoft Outlook using macros
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have been working with this code. I need to take just the body from a new email and place it in a text file. I'm filtering by subject and moving it to a sub folder. I didn't write most of this code and have been trying to get a better understanding of it.
I can't determine what part of the script controls that. I don't need any other part of the email.
Option Explicit
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olNs As Outlook.NameSpace
Dim Inbox As Outlook.MAPIFolder
Set olNs = Application.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Set Items = Inbox.Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
SaveMailAsFile Item ' call sub
End If
End Sub
Public Sub SaveMailAsFile(ByVal Item As Object)
Dim olNs As Outlook.NameSpace
Dim Inbox As Outlook.MAPIFolder
Dim SubFolder As Outlook.MAPIFolder
Dim Items As Outlook.Items
Dim ItemSubject As String
Dim NewName As String
Dim RevdDate As Date
Dim Path As String
Dim Ext As String
Dim i As Long
Set olNs = Application.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Set Items = Inbox.Items.Restrict("[Subject] = 'Auto~! Keep ad the same'")
Path = Environ("USERPROFILE") & "DesktopTemp"
ItemSubject = Item.Subject
RevdDate = Item.ReceivedTime
Ext = "txt"
For i = Items.Count To 1 Step -1
Set Item = Items.Item(i)
DoEvents
If Item.Class = olMail Then
Debug.Print Item.Subject ' Immediate Window
Set SubFolder = Inbox.Folders("SSX") ' <--- Update Fldr Name
ItemSubject = Format(RevdDate, "YYYYMMDD-HHNNSS") _
& " - " & _
Item.Subject & Ext
ItemSubject = FileNameUnique(Path, ItemSubject, Ext)
Item.SaveAs Path & ItemSubject, olTXT
Item.Move SubFolder
End If
Next
Set olNs = Nothing
Set Inbox = Nothing
Set SubFolder = Nothing
Set Items = Nothing
End Sub
'// Check if the file exists
Private Function FileExists(FullName As String) As Boolean
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(FullName) Then
FileExists = True
Else
FileExists = False
End If
Exit Function
End Function
'// If the same file name exist then add (1)
Private Function FileNameUnique(Path As String, _
FileName As String, _
Ext As String) As String
Dim lngF As Long
Dim lngName As Long
lngF = 1
lngName = Len(FileName) - (Len(Ext) + 1)
FileName = Left(FileName, lngName)
Do While FileExists(Path & FileName & Chr(46) & Ext) = True
FileName = Left(FileName, lngName) & " (" & lngF & ")"
lngF = lngF + 1
Loop
FileNameUnique = FileName & Chr(46) & Ext
Exit Function
End Function
vba outlook outlook-vba
add a comment |
I have been working with this code. I need to take just the body from a new email and place it in a text file. I'm filtering by subject and moving it to a sub folder. I didn't write most of this code and have been trying to get a better understanding of it.
I can't determine what part of the script controls that. I don't need any other part of the email.
Option Explicit
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olNs As Outlook.NameSpace
Dim Inbox As Outlook.MAPIFolder
Set olNs = Application.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Set Items = Inbox.Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
SaveMailAsFile Item ' call sub
End If
End Sub
Public Sub SaveMailAsFile(ByVal Item As Object)
Dim olNs As Outlook.NameSpace
Dim Inbox As Outlook.MAPIFolder
Dim SubFolder As Outlook.MAPIFolder
Dim Items As Outlook.Items
Dim ItemSubject As String
Dim NewName As String
Dim RevdDate As Date
Dim Path As String
Dim Ext As String
Dim i As Long
Set olNs = Application.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Set Items = Inbox.Items.Restrict("[Subject] = 'Auto~! Keep ad the same'")
Path = Environ("USERPROFILE") & "DesktopTemp"
ItemSubject = Item.Subject
RevdDate = Item.ReceivedTime
Ext = "txt"
For i = Items.Count To 1 Step -1
Set Item = Items.Item(i)
DoEvents
If Item.Class = olMail Then
Debug.Print Item.Subject ' Immediate Window
Set SubFolder = Inbox.Folders("SSX") ' <--- Update Fldr Name
ItemSubject = Format(RevdDate, "YYYYMMDD-HHNNSS") _
& " - " & _
Item.Subject & Ext
ItemSubject = FileNameUnique(Path, ItemSubject, Ext)
Item.SaveAs Path & ItemSubject, olTXT
Item.Move SubFolder
End If
Next
Set olNs = Nothing
Set Inbox = Nothing
Set SubFolder = Nothing
Set Items = Nothing
End Sub
'// Check if the file exists
Private Function FileExists(FullName As String) As Boolean
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(FullName) Then
FileExists = True
Else
FileExists = False
End If
Exit Function
End Function
'// If the same file name exist then add (1)
Private Function FileNameUnique(Path As String, _
FileName As String, _
Ext As String) As String
Dim lngF As Long
Dim lngName As Long
lngF = 1
lngName = Len(FileName) - (Len(Ext) + 1)
FileName = Left(FileName, lngName)
Do While FileExists(Path & FileName & Chr(46) & Ext) = True
FileName = Left(FileName, lngName) & " (" & lngF & ")"
lngF = lngF + 1
Loop
FileNameUnique = FileName & Chr(46) & Ext
Exit Function
End Function
vba outlook outlook-vba
add a comment |
I have been working with this code. I need to take just the body from a new email and place it in a text file. I'm filtering by subject and moving it to a sub folder. I didn't write most of this code and have been trying to get a better understanding of it.
I can't determine what part of the script controls that. I don't need any other part of the email.
Option Explicit
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olNs As Outlook.NameSpace
Dim Inbox As Outlook.MAPIFolder
Set olNs = Application.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Set Items = Inbox.Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
SaveMailAsFile Item ' call sub
End If
End Sub
Public Sub SaveMailAsFile(ByVal Item As Object)
Dim olNs As Outlook.NameSpace
Dim Inbox As Outlook.MAPIFolder
Dim SubFolder As Outlook.MAPIFolder
Dim Items As Outlook.Items
Dim ItemSubject As String
Dim NewName As String
Dim RevdDate As Date
Dim Path As String
Dim Ext As String
Dim i As Long
Set olNs = Application.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Set Items = Inbox.Items.Restrict("[Subject] = 'Auto~! Keep ad the same'")
Path = Environ("USERPROFILE") & "DesktopTemp"
ItemSubject = Item.Subject
RevdDate = Item.ReceivedTime
Ext = "txt"
For i = Items.Count To 1 Step -1
Set Item = Items.Item(i)
DoEvents
If Item.Class = olMail Then
Debug.Print Item.Subject ' Immediate Window
Set SubFolder = Inbox.Folders("SSX") ' <--- Update Fldr Name
ItemSubject = Format(RevdDate, "YYYYMMDD-HHNNSS") _
& " - " & _
Item.Subject & Ext
ItemSubject = FileNameUnique(Path, ItemSubject, Ext)
Item.SaveAs Path & ItemSubject, olTXT
Item.Move SubFolder
End If
Next
Set olNs = Nothing
Set Inbox = Nothing
Set SubFolder = Nothing
Set Items = Nothing
End Sub
'// Check if the file exists
Private Function FileExists(FullName As String) As Boolean
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(FullName) Then
FileExists = True
Else
FileExists = False
End If
Exit Function
End Function
'// If the same file name exist then add (1)
Private Function FileNameUnique(Path As String, _
FileName As String, _
Ext As String) As String
Dim lngF As Long
Dim lngName As Long
lngF = 1
lngName = Len(FileName) - (Len(Ext) + 1)
FileName = Left(FileName, lngName)
Do While FileExists(Path & FileName & Chr(46) & Ext) = True
FileName = Left(FileName, lngName) & " (" & lngF & ")"
lngF = lngF + 1
Loop
FileNameUnique = FileName & Chr(46) & Ext
Exit Function
End Function
vba outlook outlook-vba
I have been working with this code. I need to take just the body from a new email and place it in a text file. I'm filtering by subject and moving it to a sub folder. I didn't write most of this code and have been trying to get a better understanding of it.
I can't determine what part of the script controls that. I don't need any other part of the email.
Option Explicit
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olNs As Outlook.NameSpace
Dim Inbox As Outlook.MAPIFolder
Set olNs = Application.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Set Items = Inbox.Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
SaveMailAsFile Item ' call sub
End If
End Sub
Public Sub SaveMailAsFile(ByVal Item As Object)
Dim olNs As Outlook.NameSpace
Dim Inbox As Outlook.MAPIFolder
Dim SubFolder As Outlook.MAPIFolder
Dim Items As Outlook.Items
Dim ItemSubject As String
Dim NewName As String
Dim RevdDate As Date
Dim Path As String
Dim Ext As String
Dim i As Long
Set olNs = Application.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Set Items = Inbox.Items.Restrict("[Subject] = 'Auto~! Keep ad the same'")
Path = Environ("USERPROFILE") & "DesktopTemp"
ItemSubject = Item.Subject
RevdDate = Item.ReceivedTime
Ext = "txt"
For i = Items.Count To 1 Step -1
Set Item = Items.Item(i)
DoEvents
If Item.Class = olMail Then
Debug.Print Item.Subject ' Immediate Window
Set SubFolder = Inbox.Folders("SSX") ' <--- Update Fldr Name
ItemSubject = Format(RevdDate, "YYYYMMDD-HHNNSS") _
& " - " & _
Item.Subject & Ext
ItemSubject = FileNameUnique(Path, ItemSubject, Ext)
Item.SaveAs Path & ItemSubject, olTXT
Item.Move SubFolder
End If
Next
Set olNs = Nothing
Set Inbox = Nothing
Set SubFolder = Nothing
Set Items = Nothing
End Sub
'// Check if the file exists
Private Function FileExists(FullName As String) As Boolean
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(FullName) Then
FileExists = True
Else
FileExists = False
End If
Exit Function
End Function
'// If the same file name exist then add (1)
Private Function FileNameUnique(Path As String, _
FileName As String, _
Ext As String) As String
Dim lngF As Long
Dim lngName As Long
lngF = 1
lngName = Len(FileName) - (Len(Ext) + 1)
FileName = Left(FileName, lngName)
Do While FileExists(Path & FileName & Chr(46) & Ext) = True
FileName = Left(FileName, lngName) & " (" & lngF & ")"
lngF = lngF + 1
Loop
FileNameUnique = FileName & Chr(46) & Ext
Exit Function
End Function
vba outlook outlook-vba
vba outlook outlook-vba
edited Mar 22 at 1:03
0m3r
8,07292555
8,07292555
asked Mar 21 at 21:03
Jonathan SavasJonathan Savas
103
103
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Quick example here
Option Explicit
Private Sub Example()
Dim FSO As New FileSystemObject
Dim TS As TextStream
Dim olMsg As Outlook.MailItem
Set olMsg = ActiveExplorer.selection.Item(1)
Set TS = FSO.OpenTextFile("C:TempEmail.txt", ForAppending, True)
TS.Write (olMsg.Body)
TS.Close
End Sub
TS.Write (olMsg.Body) this portion is what references only the messages body ?
– Jonathan Savas
Mar 22 at 15:37
@JonathanSavas. Yes. In your original post you useSaveAswhich saves the entire message in text format..Bodyis the text body of the MailItem. 0m3r has shown you how to write the text body of the currently selected email to a file. Is this enough for you to modify your macro?
– Tony Dallimore
Mar 22 at 17:35
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55289218%2fonly-output-the-message-body-to-txt-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Quick example here
Option Explicit
Private Sub Example()
Dim FSO As New FileSystemObject
Dim TS As TextStream
Dim olMsg As Outlook.MailItem
Set olMsg = ActiveExplorer.selection.Item(1)
Set TS = FSO.OpenTextFile("C:TempEmail.txt", ForAppending, True)
TS.Write (olMsg.Body)
TS.Close
End Sub
TS.Write (olMsg.Body) this portion is what references only the messages body ?
– Jonathan Savas
Mar 22 at 15:37
@JonathanSavas. Yes. In your original post you useSaveAswhich saves the entire message in text format..Bodyis the text body of the MailItem. 0m3r has shown you how to write the text body of the currently selected email to a file. Is this enough for you to modify your macro?
– Tony Dallimore
Mar 22 at 17:35
add a comment |
Quick example here
Option Explicit
Private Sub Example()
Dim FSO As New FileSystemObject
Dim TS As TextStream
Dim olMsg As Outlook.MailItem
Set olMsg = ActiveExplorer.selection.Item(1)
Set TS = FSO.OpenTextFile("C:TempEmail.txt", ForAppending, True)
TS.Write (olMsg.Body)
TS.Close
End Sub
TS.Write (olMsg.Body) this portion is what references only the messages body ?
– Jonathan Savas
Mar 22 at 15:37
@JonathanSavas. Yes. In your original post you useSaveAswhich saves the entire message in text format..Bodyis the text body of the MailItem. 0m3r has shown you how to write the text body of the currently selected email to a file. Is this enough for you to modify your macro?
– Tony Dallimore
Mar 22 at 17:35
add a comment |
Quick example here
Option Explicit
Private Sub Example()
Dim FSO As New FileSystemObject
Dim TS As TextStream
Dim olMsg As Outlook.MailItem
Set olMsg = ActiveExplorer.selection.Item(1)
Set TS = FSO.OpenTextFile("C:TempEmail.txt", ForAppending, True)
TS.Write (olMsg.Body)
TS.Close
End Sub
Quick example here
Option Explicit
Private Sub Example()
Dim FSO As New FileSystemObject
Dim TS As TextStream
Dim olMsg As Outlook.MailItem
Set olMsg = ActiveExplorer.selection.Item(1)
Set TS = FSO.OpenTextFile("C:TempEmail.txt", ForAppending, True)
TS.Write (olMsg.Body)
TS.Close
End Sub
answered Mar 21 at 23:32
0m3r0m3r
8,07292555
8,07292555
TS.Write (olMsg.Body) this portion is what references only the messages body ?
– Jonathan Savas
Mar 22 at 15:37
@JonathanSavas. Yes. In your original post you useSaveAswhich saves the entire message in text format..Bodyis the text body of the MailItem. 0m3r has shown you how to write the text body of the currently selected email to a file. Is this enough for you to modify your macro?
– Tony Dallimore
Mar 22 at 17:35
add a comment |
TS.Write (olMsg.Body) this portion is what references only the messages body ?
– Jonathan Savas
Mar 22 at 15:37
@JonathanSavas. Yes. In your original post you useSaveAswhich saves the entire message in text format..Bodyis the text body of the MailItem. 0m3r has shown you how to write the text body of the currently selected email to a file. Is this enough for you to modify your macro?
– Tony Dallimore
Mar 22 at 17:35
TS.Write (olMsg.Body) this portion is what references only the messages body ?
– Jonathan Savas
Mar 22 at 15:37
TS.Write (olMsg.Body) this portion is what references only the messages body ?
– Jonathan Savas
Mar 22 at 15:37
@JonathanSavas. Yes. In your original post you use
SaveAs which saves the entire message in text format. .Body is the text body of the MailItem. 0m3r has shown you how to write the text body of the currently selected email to a file. Is this enough for you to modify your macro?– Tony Dallimore
Mar 22 at 17:35
@JonathanSavas. Yes. In your original post you use
SaveAs which saves the entire message in text format. .Body is the text body of the MailItem. 0m3r has shown you how to write the text body of the currently selected email to a file. Is this enough for you to modify your macro?– Tony Dallimore
Mar 22 at 17:35
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55289218%2fonly-output-the-message-body-to-txt-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown