Newbie Question

  • Thread starter Thread starter Dale
  • Start date Start date
D

Dale

Hello all!

Can anyone guide me as to how I might accomplish this?

1. I need to select (highlight) about 11 emails in the Inbox.
2. Save the bodies out to 11 individual text files.

I assume I would need to create an array of file names or build the names on
the fly.

The filename format would be "SALE" & (4 character date value) & (alpha
character (a thru k)) & ".txt"

Any help would be appreciated but a little push toward how I would
programmatically identify and individual email message would go a long way.

Regards
Dale
 
Hi Dale,
1. I need to select (highlight) about 11 emails in the Inbox.

which 11 mails do you want to select, the first 11 or maybe the last?
The filename format would be "SALE" & (4 character date value)

What is a 4 character date value? AFAIK you need at least 6 characters.

Based on you have selected your mails already, you can loop through it,
e.g.:

'<DieseOutlookSitzung>
Public Sub LoopMailFolder()
Dim oSel as Outlook.Selection
Dim obj as Object
Dim cnt as Long
Set oSel=Application.ActiveExplorer.Selection
cnt=oSel.Count
If cnt=11 Then
For i=1 to cnt
Set obj=oSel(i)
If TypeOf obj Is Outlook.MailItem Then
ExportMailToTxt obj, chr$(96+i)
Endif
Next
Endif
End Sub

Public Function ExportMailToTxt(oMail As Outlook.MailItem, _
sExt as String _
) As Boolean
On Error Resume Next
Dim sPath As String: sPath = "c:\mails\"
Dim sName As String
Dim sFile As String
Dim dtDate As Date

sName = oMail.Subject
ReplaceCharsForFileName sName
dtDate = Date
sName = "SALE" & Format(dtDate, "yyyymmdd", vbMonday, vbFirstJan1) _
& sExt & ".txt"
oMail.SaveAs sPath & sName, olTXT
ExportMailToTxt = (Err.Number = 0)
End Function
'</DieseOutlookSitzung>
 
Michael,

Thanx for your response and your kind submission of code for me to tear
apart. I'm very new to Outlook VBA.

I've been attempting to see how your code works in the VBA Editor. As I
step thru the code it chokes when I get to "ReplaceCharsForFileName".

VBA seems to think this line is calling another Sub or Function (not
defined error).

Is this actually what we're trying to do in this instance? I'm not sure....

Regards
Dale
 
Sorry Michael, I did not see your direct question about the date.

The 4 characters represent a month and a day only. For instance October 7th
would be represented by 1007. A string variable would be sufficient to
store that portion. I was going to have an inputbox come up to gather the
necessary string of digits.

Thanx
Dale
 
A string variable would be sufficient to
store that portion. I was going to have an inputbox come up to gather the
necessary string of digits.
Ok.

Dim dtDate As Date
...
dtDate = Date

So these lines are unnecessary to.
Format(dtDate, "yyyymmdd", vbMonday, vbFirstJan1)

And replace this through your own variable.
 
Michael,

Slicker than steping in dog doo-doo on wet grass! Thank you for your help.

I added a shell statement to a text editor to open all of these files once
they were saved.

Here is my/your final code (if you are interested)

Dale


Public Sub SAVESALES() 'LoopMailFolder()

Dim oSel As Outlook.Selection
Dim obj As Object
Dim cnt As Long
Dim SALEDate As String

Set oSel = Application.ActiveExplorer.Selection
cnt = oSel.Count

SALEDate = InputBox("What is today's date?")

If cnt = 11 Then
For i = 1 To cnt
Set obj = oSel(i)
If TypeOf obj Is Outlook.MailItem Then
ExportMailToTxt obj, Chr$(96 + i), SALEDate
End If
Next
End If

Shell "d:\Program Files\UltraEdit\uedit32.exe Q:efiles\email\sale" &
SALEDate & "*.txt", vbNormalFocus

End Sub

Public Function ExportMailToTxt(oMail As Outlook.MailItem, _
sExt As String, sDate As String _
) As Boolean
On Error Resume Next
Dim sPath As String: sPath = "Q:efiles\email\" '"c:\"
Dim sName As String

sName = "SALE" & sDate _
& sExt & ".txt"
oMail.SaveAs sPath & sName, olTXT
ExportMailToTxt = (Err.Number = 0)
End Function
 
Hi Dale,

thank you for your feedback.
SALEDate = InputBox("What is today's date?")

For the current date you could have kept the former code. That would be
more comfortable for the user. Just replace the format string by a
string you´d like to (e.g. "mmdd" for the result 1007, if it is Oct.,
7th).

What is the programm "uedit32.exe" in UltraEdit doing?
 
Michael

As for the "original" date code, what are you saying? You would still have
to accept that via inputbox wouldn't you? Maybe get it from the system
date? Are you saying that you could type in the date in any format and have
it submit (to the macro) the proper string of digits? I work at a small
shop and we have a well known procedure for these files so typing 1007 is no
big deal.

As far as what is (programatically) happening in UltraEdit, the answer is
currently nothing. The data files consist of a 5 line email header and a
varying number of data records. A co-worker manually identifies the number
of records per file and documents this for quality control checking when the
job is processed. That co-worker has a good grasp of macros within
UltraEdit and has indicated he might try to code something to automate that
facet.

Again, thanx for your help. I had the beginnings of something for a Outlook
macro to do the save-to-file task you helped with but your code was right
there. Since this was my first attempt at dealing with Outlook, I would
have been at the trial and error stage for some time.
 
Hello Dale,
Are you saying that you could type in the date in any format and have
it submit (to the macro) the proper string of digits?

Not sure, if I understand your question correct...

The Date function returns the current system date. The Format function
allows you to format a value as you like to.

E.g.: Format(Date,"mmdd",vbMonday,vbFirstJan1) returns 1008 for today.

"m" is for the month in one digit (if possible), "mm" for two digits,
"mmm" returns the month written out. "d" is analogous for the day, "y"
for the year.

Of course, typing in the date is no big deal - but a little more
error-prone.
 
Back
Top