Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I also believe that we all can contribute to each other's growth by sharing knowlege and experiences. I would love to take my skills and help people around the world solve problems..."

Geography

Where in the world do Tek-Tips members come from?
joemajestee (Programmer)
31 May 12 11:02
Hello,

I have a macro in Excel 2003 that creates emails in Outlook 2003 using a .oft file. The emails end up with blank lines because not all of the records contain data for each line. Right now, the macro displays the emails so the user can delete all the blank lines before sending. I'm wondering if there is a way to use VBA to automate some of that.

Next is a sample of the emails, the bullets that are circles as opposed to dots are supposed to be indented.

CODE -->

• The entry number must appear in the PDF file name. • • One email with exhibit materials should be submitted per individual entry. • No other exhibits are required for this entry., • • , o o o o o o o • Be sure to review the judging criteria for your entry prior to submitting your exhibit. • •

I looked at the idea of using REPLACE to eliminate the listitems but I could not find a way to do that because the html wasn't consistent.

Thanks

Joe
SkipVought (Programmer)
31 May 12 11:13


hi,

How does the program get the data?

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

joemajestee (Programmer)
31 May 12 13:10
Hi Skip.
Sorry, juggling lots of things today.

Not sure what you mean. But here's some of the excel code:

CODE -->

Dim OutApp As Object, OutMail As Object Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItemFromTemplate(strTemplate) strHTMLbody = OutMail.htmlbody ... replace stuff in strHTMLbody with some of the current row's content OutMail.htmlbody = strHTMLbody OutMail.Subject = Replace(OutMail.Subject, Replace(Cells(1, c1.Column).Value, " ", ""), strReplacement)

Does this answer your question?
SkipVought (Programmer)
31 May 12 13:14


Let's try this...
[quote]The emails end up with blank lines because not all of the records contain data for each line.[/quote
Where do "all of the records" come from, that you refer to?

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

joemajestee (Programmer)
31 May 12 13:39
OK, thanks for the clarification.
The excel spreadsheet has in row one what I'm gonna call headers.
header1, header2, header2...header50

Each row has unique data
record1, record2, etc.

The outlook template file has text (formatted html) like this:

Hello header1,
Your entry number is header2 and it's name is header3.
Here is a list of stuff you have to do before the judges come out:

  • header4

  • header5

  • header6

  • header7

  • header8


Thanks for entering, header1.

The macro goes through row by row and creates a separate email for each row, substituting the headern text it finds with the current row, column n's value. Most of the rows won't have data in all of the list item columns. If the current row has nothing in the same column as header6, then the macro replaces "header6" with "".

Hope that's clearer.
SkipVought (Programmer)
31 May 12 13:46
Well then, the program ought to check each row (record) for the presence of data, before passing it to the message.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

joemajestee (Programmer)
31 May 12 14:12
I'm not creating the html on the fly. All of the placeholders (headers) that might contain data are in the template. I can check for data, but I'd still have the problem of "headern" still being in the resulting email.
SkipVought (Programmer)
31 May 12 14:19


Header/row: who cares what YOU call it. Before placing the data in your message, your program must TEST the Header/row data for the presence of data!

If this is NOT in your program, then why are you posting in a VBA (program) forum?

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

joemajestee (Programmer)
31 May 12 15:03
Because the only answer, if there is one, will be VBA.

The emails are created using VBA and an existing outlook template. The template has placeholders for all of the possible data from each record. If the record doesn't require all of the placeholders, the placeholders remain in the template and have to be manually deleted. It would be better if they could be programmatically deleted.

I used the word header to distinguish it from data because that is how the macro works, sort of like a mail merge.

sample worksheet
FirstName---LastName---Entry#---Task1---Task2---Task3
Herman--------Munster--------36B--------Clean-----Paint-----------------
Gomez---------Addams--------32B---------Call--------------------Cook

sample template:
FirstName LastName:
Your entry number is Entry#.
Do these things:
  • Task1
  • Task2
  • Task3
Thanks for your support, FirstName

Results:
-------------------------------------------------
Herman Munster:
Your entry number is 36B.
Do these things
  • Clean
  • Paint
Thanks for your support, Herman
-------------------------------------------------
Gomez Addams:
Your entry number is 32B.
Do these things
  • Call
  • Cook
Thanks for your support, Gomez
-------------------------------------------------

What am I not telling you?
SkipVought (Programmer)
31 May 12 15:16


...which is the inherent problem with source data that is not normalized!

You would be better served with source data like...

FirstName LastName Entry# Task
Herman Munster 36B Clean
Herman Munster 36B Paint
Gomez Addams 32B Call
Gomez Addams 32B Cook

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

dhulbert (TechnicalUser)
1 Jun 12 8:27

Skip.

Not sure if normalised data would help here,

Person 1 has 5 items of data
person 2 has 3 itmes of data
Person 3 has 2 items of data

If he has 5 place holders in the e-mail template and there is only data for 3 then the other 2 will remain empty and will display a blank line.

What I think the guy is really looking for is a way to delete empty place holders AFTER the e-mail has been generated but before it is sent to the recipient.

I love deadlines. I like the whooshing sound they make as they fly by
Douglas Adams
(1952-2001)

joemajestee (Programmer)
1 Jun 12 8:41
yes, that is correct, thank you. Skip?
SkipVought (Programmer)
1 Jun 12 9:09


The problem is with your template.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close