Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Word take field contain to put it in an email automatically 1

Status
Not open for further replies.

scorney

Technical User
Sep 15, 2003
115
CA
Hello Group !

I'm looking for a way to grab (copy) data in a known place in a MS Word file (sheet) and paste it in an email.

I have already an hyperlink in the word document build stating If you click on this button (email button, but it's set up as mail) an email will be sent out approving this document.

I would like to copy at 2 places 2 different order number and place it in either the subject or message. the information reside within the same document.

Let say for example:

Customer Order: 123456789
Sales Order: 987654321

I'd like to copy both 123... & 9876...
and paste it in the email.

It can be a sort of variable field or VB script but cannot figure how to do it. The email thing with subject pre-define and email address pre-define is good, it work fine, but i'd like to have more detail in the email without having to play with the hyperlink at each single time I'm creating a new form...

Thanks.
Sylvain
 
scorney,

It would help to know how your Word document is set up. Are the two items you want to copy in formfields, are they bookmarked, or what? There has to be some way to absolutely identify them every time you want to send the e-mail, but before we can be of much help we need to know what your document is doing.

[glasses]

----------------------------------------------------------------------------------
"A committee is a life form with six or more legs and no brain." -- L. Long
 
WalkerEvans,

The Document is a Method of Procedure and it has to be costomize for each single job and at the top of this document I'm entering P.O # Sales Order in a simple text form field (area grayed out) It's just for pointing where to enter information.
It has 5 pages and at the end of the Document I have added a button which is used as Hyperlink to email. In this hyperlink I can pre-define message, but I want to make life easier to all user and not having to edit this hyperlink and add manually the order # and sales order #.

I can't really share this document, but if you would like to see how I set it up I can make a template and send it to you, you'll have PO, Sales Order and the hyperlink, just enough information to see exactly what I'm looking for.

Thanks a lot for your help,
Regards,
Sylvain
 
scorney,

There's really no need to see the document, as you have (I believe) answered the question regarding the way the document is set up. If I understand correctly, you have this set up as a form, with both of the data items you want to copy being entered in formfields. If this is correct, each of the formfields has a distinct Bookmark, such as Text1, Text2, etc.; you can see these with "Form Field Options" on the Forms Toolbar.

If I read your response correctly, you should be able to copy the appropriate formfields into your e-mail without any problems.

I'm being called into an immediate unscheduled staff meeting, which is never good news; I'll check back later.

----------------------------------------------------------------------------------
"A committee is a life form with six or more legs and no brain." -- L. Long
 
WalkerEvans,

I'm sorry for this staff meetings, I've seen many of them happening on Tuesday or Wednesday !!! Not a good day for an unexpected staff meeting..... :(

For the Document...
I didn't setup bookmark on these so far, but you have a good point If I bookmark them then it shouldn't be a problem to insert them in the email automatically...

I just tried but cannot figure out is the bookmark has to be in subject between {} this is just what i tried and in the subject I see MOP has been approved {ProjectNumber} {OrderNumber}..

You bring me to the right direction...

Thanks for your great help...
Hope nothing bad happened on the staff meeting....

Sylvain

 
I am confused. Are these in formfields, or not? Did you use the Forms toolbar to make them? You state "text formfield", so that does sound like formfields.

In which case, as Walker states, use the formfield result.

faq219-2884

Gerry
My paintings and sculpture
 
Fumei,

yes it is formfield. sorry about the confusion..
 
So you can get the content by:
Code:
Dim strCustOrder As String
strCustOrder = ActiveDocument.FormFields("CustomerOrder").Result
If you want to use a string variable. Or you could simply pass the .Result itself into the message body. Whatever.

Assuming the formfield is named CustomerOrder. Use whatever is the name it has. Hopefully you have indeed named them, and not kept the default names.

faq219-2884

Gerry
My paintings and sculpture
 

I'm back, at least for a short time. FYI, something "bad" did happen in our meeting, at least from one person's point of view. A person was pulled (yanked, actually) off my project, which was very bad news for him, but very good news for me. I've been doing my work and having to correct almost all of his for some time now; it's going to be easier and quicker just to do the whole thing myself.

On to your project: As Gerry states, since these are indeed formfields they already have a named Bookmark which you can see on the Forms Toolbar as I noted before; the default names (Text1, etc.) can be modified to something less generic that will be easier to remember and associate with the task. It is always a good idea to use names that have some meaning rather than sticking with the default names assigned by the system. If you stay with the system names, when anyone else takes over they're going to have a hard time figuring out what's what. That may not be a problem with a really small project, but it can be a killer if the project grows.

In any case, you should have what you need to complete your macro programming. Let us know if you have further problems.

[thumbsup2]

----------------------------------------------------------------------------------
"A committee is a life form with six or more legs and no brain." -- L. Long
 
Guys, I'm sorry I'm really newbie to this VB thing...

How and where should I add the line you provided to me...

I created a click button on the word file then right-click on it and view code.

I added this line with the right formfield names and i don't know what to add to have an email send out by clicking on this button...

What would be the VB code ? I google a lot but can't figure out...

Any help would be much appreciated....

Thanks again for your help.
Sylvain
 
I am confused. Do you, or do you not, have the email part working. You state:
The email thing with subject pre-define and email address pre-define is good, it work fine
THAT sounds to me that you have the message working. You just wanted to know how to get the text from the formfields.

You have been told how to do that.

So...what exactly is the problem?

faq219-2884

Gerry
My paintings and sculpture
 
sorry Gerry,

I'm not expressing myself properly...

I tried to added the portion you mention above:

Dim strCustOrder As String
strCustOrder = ActiveDocument.FormFields("CustomerOrder").Result

But nothing work, not even the email portion...
I tried too many things since the beginning and now I'm more confused. I used Routing.slip VB script and massage it to make it work with the lines you've sent to me, but nothing is poping up. When I click on the button nothing happen anymore. I don't want to use Routing Slip, I just wanted to use the script has a start.
I'm really newbie on this, I know I should know how to walk first, then run, but I don't have enough time...

I created my MS Word file, then at the end I added a button right-click on it view code and here we go I have the VB open.
The script look like this:

Private Sub CommandButton1_Click()
ActiveDocument.SendMail
With ActiveDocument.SendMail
.Subject = "Your MOP" $ProjectNumber; "has been approved"
.AddRecipient "xwz@isp.com"
.AddRecipient "qwerty@isp.com"
.Delivery = wdAllAtOnce
Dim strCustomerOrder As String
strCustomerOrder = ActiveDocument.FormFields CustomerOrder.Result
Dim strProjectNumber As String
strProjectNumber = ActiveDocument.FormFields ProjectNumber.Result

End With
ActiveDocument.SendMail


End Sub



Hope this help to understand What I want to do and where I'm standing at now.

Thanks...
 
First, does your:

strCustomerOrder = ActiveDocument.FormFields CustomerOrder.Result

look like what I posted?

strCustOrder = ActiveDocument.FormFields("CustomerOrder").Result


Second, although you make the string variable the result - although, you actually don't as your syntax is wrong - you don't do anything else with them.

I don't want to use Routing Slip, I just wanted to use the script has a start.
You are not posting whatever "the script", even when asked. And again, you stated that you DID have something working.

I am not even sure you can do what I think you want...but then I am not sure what you want.

faq219-2884

Gerry
My paintings and sculpture
 
Gerry,

The Word file is a Method of Procedure costomized for each particular work to be perform on customers network, which I'm sending the MOP for approval to their engineer. I want them just to click on the button included/build in the Word file so that it send to pre-define address list the email stating this MOP has been approved.

I'm trying to do this in word but If it's not do-able then I'll look into PDF or something else, but if it's do-able then It's perfect, because it would save a fortune to my group as we would have to buy new software...Acrobat, etc..

Thanks a lot for your patience !!!
 
You can certainly send the active document as an attachment with Word. But it sounds...and AGAIN you are not stating clearly what you want to do...like you want to put text into the message area. I am not sur eyou can do that.

Are you using Outlook? If so, then use Outlook to make the message, then you can put whatever you want into the message area.

faq219-2884

Gerry
My paintings and sculpture
 
I'm using Outlook, but i don't know about my customers....

What I just found on the net is that I could use just a regular hyperlink in the file and it would send an email to who ever that i would have mention in the hyperlink itself.
Something like mailto:qwerty@isp.com?subject=Your MOP has Been Approved, but then I have to add the ProjectNumber formfield and CustomerOrder formfield...

I don't know if it's easier than just trying to make it work with VB... and the customer wouldn;t have to enable the macro either.. as the customer as he read the document he could just click on the hyperlink and the mail application will open with the subject pre-filled I just need to verify how the message could contain the OrderNumber and CustomerOrder and add it to the hyperlink.
 
You are confusing the Subject, with the Body. Word can email with whatever you want as the subject. It can not put text into the body.
Something like mailto:qwerty@isp.com?subject=Your MOP has Been Approved, but then I have to add the ProjectNumber formfield and CustomerOrder formfield...
So it can easily do the first part, but it can not do the second part, the formfield results.


It can put the document into the body, but as a piece. You can not selectively edit the message body. At least not natively as far as I know. However, this is not my area of expertise. When I want to send email with message body content something else, I make an instance of Outlook and use it. That way, I can do whatever I want, as I am using Outlook.

faq219-2884

Gerry
My paintings and sculpture
 

I wasn't able to get back to everyone sooner due to a committment that took me out of town Thursday; I just got back. Gerry is right in that you can't put your data directly into the body of an Outlook email, but it likely can be done indirectly - it would just take a bit more work.

Here is what I hope will be my last question: Is the body of your email a standard format, with the exception of the data we're discussing, or does it have to be custom-written for each project? If you have a standard format we can still do this, but if each email is a custom job we'll have to abandon this method, unless someone out there can pull a rabbit out of their hat.

[glasses]

----------------------------------------------------------------------------------
"A committee is a life form with six or more legs and no brain." -- L. Long
 
I'm having really hard time figuring this how it's should work.

I have this X post to
I think this is better since it's copying the word file into the email. This how it worked on the first time, but since it doesn't work, so I think I got lucky, for that time. I had .send at the begining but it didn't give option to the sender to edit the email prior to send... and it asked for authorization to Outlook because an application is trying to send email on your behalf, " Do you accept or Not".

Here is what I have and Gerry mention to add sendmail instruction at the end... I'm totally lost...

Private Sub CommandButton1()
ActiveDocument.SendMail
With ActiveDocument.MailEnvelope.Item
.Recipients.Add "scorney@isp.com"
.Recipients.Add "scorney@isp.ca"
.Subject = "I Approved the MOP."
End With
End Sub

I really detail instruction as I'm lost...

Thanks for your patience....Guys you deserved STARS...
 
Here is the final script that work !!!
but now I'm stuck with Security issue...

Private Sub CommandButton11_Click()
With ActiveDocument.MailEnvelope.Item
ActiveDocument.SendMail
.Recipients.Add "scorney@ISP.com"
.Recipients.Add "JohnDoe@sympatico.ca"
.Subject = "MOP has been Approved."
.send

End With
MsgBox "An email has been sent on your behalf with the statement The MOP has been approved"
End Sub

On my Laptop is work well..but when I send it to my counter part they click on the button but nothing happen, when they click twice then the VB screen is poping up.

They would need to set their security option to medium...

This is the issue... Is their a workaround this security settings? I can't ask every one that will use this form to change their settings ?

Let me know if you see another thing to do or should I change the way to built this form...
I'm thinking PDF form... I do have Acrobat 8.0 pro...

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top