PDA

View Full Version : Macro/VBA code help



charlie89
08-12-2014, 12:59 AM
Hey,

I am new at coding and VBA is tricky! I have a spreadsheet with a table of data that is filled out everyday at the end of each shift. I want to create a "save and send" button within excel that will save the information as a text file in a chosen location and send the data as an email to the rest of the site or a chosen mailing list. But keeping the general format in the email so its easy to read and find the information..

I've got a few lines done but i am utterly stuck!!

thanks in advance

snb
08-12-2014, 03:08 AM
You might have a look over here:

http://www.snb-vba.eu/VBA_Excelgegevens_mailen_en.html#H2

mancubus
08-12-2014, 05:21 AM
@snb

thanks for the link and for all your tutorials.


i will use it (with a slight modification, though) in my project.


For Each sh In Sheets
c01 = c01 & "<table border=1 bgcolor=#FFFFF0#>"
sn = sh.UsedRange
For j = 1 To UBound(sn)
c01 = c01 & "<tr><td>" & Join(Application.Index(sn, j), "</td><td>") & "</td></tr>"
Next
c01 = c01 & "</table><br><br>"
Next

snb
08-12-2014, 06:18 AM
@Mancubus

You're welcome ;)

mancubus
08-12-2014, 06:54 AM
and i hope new comer OP will find a solution as well. :)

charlie89
08-13-2014, 02:32 AM
thank you, i have edited the code to work for my particular needs. How do I keep the formatting? At the moment the emails are coming out rubbish and really hard to read!

Also, how would I edit the code so the date is automatically updated in the subject field of the email?

I know i'm asking alot, but thank you in advance!!

mancubus
08-13-2014, 05:29 AM
can you post a sample workbook and screenshot of a sample email.

charlie89
08-13-2014, 05:38 AM
I have managed to get the code to copy the content and format of what is in excel. Happy!

BUT now my command button doesn't work. Where on the code can i put the macro for the command button to send email...?? Not happy!

thank you, I tried posting the code i'm using but it wouldn't let me!

charlie89
08-13-2014, 05:51 AM
i've done it :). thanks for all the help!!

mancubus
08-13-2014, 06:00 AM
if it's a form control (Button 1), right click the button and select Assign Macro, if it's an activex control (CommandButton1), double click the button (VBE window will be opened), copy your code between automatically inserted Private Sub CommandButton1_Click() and End Sub lines.


ps: before doing this click Design Mode in Controls group in Developer tab.