PDA

View Full Version : Solved: Creating an eMail from a Bookmark



Shezageek
01-23-2009, 06:31 PM
I have a very large project that calls in many documents from a command button and checkboxes. Each document is wrapped in a bookmark. When the project is completed, there may be as many as 50 different documents that are now all part of ONE document. Is there a way to create an email from just one of the bookmarked documents?

Thanks
S

lucas
01-23-2009, 06:44 PM
Something along these lines?
"to" is the name of the bookmark in this example:
.body =ActiveDocument.Bookmarks("to").Range.Text

lucas
01-23-2009, 06:52 PM
Sub eMailActiveDocument()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save
With EmailItem
.Subject = "Insert Subject Here"
.Body = ActiveDocument.Bookmarks("bodytext").Range.Text
.To = "User@Domain.Com"
.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Attachments.Add Doc.FullName
' .Send
.Display
End With

Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub

lucas
01-23-2009, 06:56 PM
I just noticed that you need to remove or comment this line or it will attach the document to the email also:


.Attachments.Add Doc.FullName

Shezageek
01-23-2009, 07:30 PM
This is the code I used, but I got an error. I have attached a jpg of the error as well.


Private Sub cmdTMAuth_Click()
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem

Me.Hide
Set olApp = CreateObject("Outlook.Application")
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = ""
.CC = ""
.BCC = ""
.Subject = "Treasury Management Service Disclosures"
.Body = ActiveDocument.Bookmarks("BKTMauthorization01").Range.Text

.Display
Unload Me
End Sub

Shezageek
01-23-2009, 08:16 PM
I am attaching another error that I got when I ran the project. Thanks for your help.

lucas
01-24-2009, 08:49 AM
You have to set a reference to the microsoft outlook object library.

in the vbe tools-references

Shezageek
01-24-2009, 10:26 AM
Thanks. It still gives me an error saying variable not defined at this line: Set EmailItem = OL.CreateItem(olMailItem).

Also, is there a way to send the bookmark as an attachment instead of body text?

Thank you for your help.

lucas
01-24-2009, 11:20 AM
Gosh, I'm tired of creating things you have.......post it.

In response to the attachment part you would have to save the bookmark text to the hard drive to attach it......

lucas
01-24-2009, 11:31 AM
Oh, and please don't post a 5mb file. Just the example of your userform if that's what it is and the bookmarked text.........just the problem at hand please.

Shezageek
01-24-2009, 02:18 PM
Sorry to bother you. Consider it solved.

lucas
01-30-2009, 09:18 AM
Sorry I couldn't help you. I, like others who contribue here have limited time. I just thought that you would understand that and make it easier for us to help you.

Reproducing an error you are having sometimes requires a little time. It seems a little unessesary when you have it on your computer.

Let us know here if you change your mind.

Shezageek
01-30-2009, 11:24 AM
You answered my question. The bookmark had to be written and saved and then emailed. The segment was such a small part of the project, I have opted not to include it as a choice. Thanks

fumei
02-03-2009, 12:53 PM
" The bookmark had to be written and saved and then emailed."

Negative. That is simply not true. It is a string, just a string. There is absolutely no problem to put any bookmark text in the email body.

"Is there a way to create an email from just one of the bookmarked documents? "

Yes, there is a way, and it is very very simple. Steve (lucas) gave it to you right away...and it works EXACTLY as it is supposed to.

Watch your required instruction closings. I notice you do not have an End With. I am assuming you have it properly in your actual code.

Bottom line? Yes, you can put the text of a bookmark into an email. It is very easy. You do NOT have to write/save it, then email it.

lucas
02-03-2009, 01:12 PM
" The bookmark had to be written and saved and then emailed."

Negative. That is simply not true. It is a string, just a string. There is absolutely no problem to put any bookmark text in the email body.



Gerry, I think this part was in reference to the question asked at post #8:


Also, is there a way to send the bookmark as an attachment instead of body text?


My reply was that I thought it would have to be saved to a file before it could be attached to the email. Maybe you could confirm or enlighten us as to whether that is actually the only way to accomplish the task.

fumei
02-04-2009, 11:04 AM
Sorry. My comment was to the "had to", in reference to the original request. The original request was to able to put a bookmark text into the body.

You can do exactly it as you first suggested.

.Body =ActiveDocument.Bookmarks("to").Range.Text

with the bookmark "to" actually existing of course.

It seemed that the OP gave up on trying to do what they originally wanted to do. They mentioned errors (and even stated they were posting images of the errors...which they did not do).

I was trying to re-iterate that you can do exactly as they originally asked. If they followed through and read your posts, well if can be done...easily.

Regarding sending anything as an attachment, yes of course it has to be a file. Therefore, to send the text of a bookmark as an attachment, yes of course you have to make it a file first. Attachments are files.

But if the original request still stands - "Is there a way to create an email from just one of the bookmarked documents? " - then the answer is still yes, you can, and exactly as you (Steve) originally responded.

lucas
02-04-2009, 11:15 AM
Yeah, the poster had a little project creep which he apparenly abandoned. Thanks for your input Gerry.