|
-
Jun 15th, 2006, 09:26 AM
#1
Thread Starter
Member
Help sending a worksheet content in email body [RESOLVED]
Hi All,
Basically I have a workbook which keeps track of how often a list of documents are reviewed. If a document's "Last reviewed date" falls beyond 180 days, conditional formatting turns the cell red to warn the owner.
What I now want to be able to do is to automatically email the owner of those documents to tell them to take action. I've written the below but this will email the entire workbook to the user rather than just the contents (or a range thereof) of a worksheet.
Can this be achieved? If so how?
Many Thanks in advance
Cliff

VB Code:
Private Sub MailDocument()
'This routene mails the customer
Dim stDocName, User As String
Dim MyMessage As Object
User = "cliff@clifforddashwrightdotcodotuk"
ColUpdateoverdue = 9
For a = 2 To Sheets.Count
Sheets(a).Activate
For x = 3 To ActiveSheet.UsedRange.Rows.Count
If Sheets(a).Cells(x, ColUpdateoverdue) = "Yes" Then
With ThisWorkbook
'.HasRoutingSlip = False
With .RoutingSlip
.Delivery = xlAllAtOnce
.Recipients = User
.Subject = "These OSM Documents are due for review"
.Message = Sheets(a).Cells(x, 8) & " Document " & Sheets(a).Cells(x, 1) & " is due for review"
.ReturnWhenDone = False
End With
.Route
End With
'just for testing only
MsgBox Sheets(a).Cells(x, 8) & " Document " & Sheets(a).Cells(x, 1) & " is due for review"
Else
End If
Next x
Next a
End Sub
Last edited by cliffw; Jun 19th, 2006 at 11:47 AM.
-
Jun 15th, 2006, 09:29 AM
#2
Re: Help sending a worksheet content in email body
Yes, you can copy the data that you want to email into a new workbook and then email that using the .SendMail method instead.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 15th, 2006, 09:42 AM
#3
Thread Starter
Member
Re: Help sending a worksheet content in email body
True - but I really wanted the content of the email to be say for example range A1:J10, appearing directly as if I'd opened an email and pasted this into the body iteself so that there are no attachments to the email ...
That possible?
Cheers
Cliff
-
Jun 15th, 2006, 09:49 AM
#4
Re: Help sending a worksheet content in email body
Yes, do you have Outlook? If not we can still do it.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 08:03 AM
#5
Thread Starter
Member
Re: Help sending a worksheet content in email body
Yes I'm using outlook
-
Jun 19th, 2006, 09:41 AM
#6
Re: Help sending a worksheet content in email body
Then you can automate Outlook from within Excel by adding a reference to Outlook and writting code to create a new email.
Or if you want to add basic text to the email body you can use the ShellExecute API and pass teh &body= argument with the text to add.
So you didnt like the create new workbook with the data and send that object instead?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 09:48 AM
#7
Thread Starter
Member
Re: Help sending a worksheet content in email body
 Originally Posted by RobDog888
So you didnt like the create new workbook with the data and send that object instead?
No not really ... it would serve a purpose but ...
The spreadsheet is a central tracking spreadsheet for a department .. the purpose of the email is to warn individual owners of documents that they should review their document which is 'logged' on this spreadsheet.
If I were to send this entire spreadsheet as an attachment, users might be tempted to update the attached version rather than the centrally stored version and hence cause me issues ...
By purely having the body of the email showing a range of cells, this would allow me to get the message across that document X needs reviewing, whilst avoiding the temptation for users to update anything other than the centrally stored tracking spreadsheet .. make sense?
 Originally Posted by RobDog888
Then you can automate Outlook from within Excel by adding a reference to Outlook and writting code to create a new email.
Can you give me a hint at the code?
Thanks 
Cliff
-
Jun 19th, 2006, 09:52 AM
#8
Re: Help sending a worksheet content in email body
Sure, but I have a massive amount of Outlook code on the forums but...
VB Code:
Option Explicit
'Add a reference to ms outlook xx.0 object library
Private Sub Command1_click()
Dim oApp As outlook.application
dim oEmail as outlook.mailitem
set oapp = new outlook.application
set oemail =- oapp.createitem(olOutlookEMailitem)
oemail.body = "Your excel range or cell(s) data"
oemail.send
set oemail = nothing
set oapp = nothing
end sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 10:04 AM
#9
Thread Starter
Member
Re: Help sending a worksheet content in email body
Thanks for this .. my knowledge of non-excell VBA is pretty shoddy ...
Using this code I get a "Compile Error; User-defined type not defined" ...
What's that about then?
-
Jun 19th, 2006, 10:05 AM
#10
Re: Help sending a worksheet content in email body
'Add a reference to ms outlook xx.0 object library
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 10:14 AM
#11
Thread Starter
Member
Re: Help sending a worksheet content in email body
Sheesh ... thanks for the speedy response ... have added the reference that I managed to miss ... doh!
But ... now I get an error saying that "olOutlookEMailitem" isn't defined ... Am I being blonde still ?
-
Jun 19th, 2006, 10:27 AM
#12
Re: Help sending a worksheet content in email body
Oops, thats what I get for freehand typing it into the reply box. It should be olMailItem.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 10:35 AM
#13
Thread Starter
Member
Re: Help sending a worksheet content in email body
Hmmm ... I did try this but thought it wasn't right because I get a 'Type mismatch' error (olMailItem seems to have a default value of '0' if this helps)
Any ideas ?
Much appreciate your help here
-
Jun 19th, 2006, 10:40 AM
#14
Re: Help sending a worksheet content in email body
Another type-o. this line should be like this.
VB Code:
set oemail = oapp.createitem(olMailitem)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 11:46 AM
#15
Thread Starter
Member
Re: Help sending a worksheet content in email body [RESOLVED]
Brilliant! 
I had wondered what the - was for ... should've known to try it ...
Works like a charm now ... Thanks again for your help 
Cliff
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|