Thank you for the question. Is there an address you would like to always have shown in the "To" field when you click the button?
Ok, I will just send a sample with a fake email that you can replace in your code. I just need a few minutes if that is ok.
Ok no problem, I have tried so many codes on different forum but it keeps saying error, the code I sent earlier is working perfactly with attaching itself to email but just can't figure out the 'Send to' bit...
How are we doing? :)
I have the email configured, just working on attaching the active document
will it be a case of me pasting in the code?
See if this works for you, there is a problem with my Outlook that prevents me from testing it now
Private Sub CommandButton1_Click()ActiveDocument.HasRoutingSlip = TrueWith ActiveDocument.RoutingSlip .subject = "Your Subject
" .AddRecipient "email@example.com" .Delivery = wdAllAtOnceEnd WithActiveDocument.RouteEnd Sub
I didn't think routing slip worked on 2007 - that is why I am having the problem - will try it again.
No it doesn't work
Try this then
Private Sub CommandButton1()ActiveDocument.SendMailWith ActiveDocument.MailEnvelope.item.Recipients.Add "firstname.lastname@example.org".subject = "Your Subject"End WithEnd Sub
no, it is still not working - do I need to delete anything otherXXX@XXXXXX.XXX ? assume I keep the " symbols???
you should only need to change the email address that is there
what message do you get?
the whole thing has frozen - hang on whilst I go in again
I put the code in, saved it and when I click on the button nothing happens at all
is Outlook open anywhere?
Can you close it?
yes hang on
i will try again
Ok, in the mean time I'll work on one more in case that doesn't work
it says compile error only comments may appear after end sub, end function or end property (???)
there shouldnt be anything after "End Sub" in your code
there is nothing
now outlook won't open either!!
Check for an outlook.exe process running on your machine and kill it
done, document has died, lost the lot, trying again on separate document
Try this instead as well
() Options.SendMailAttach = True ActiveWindow.EnvelopeVisible = True With ActiveDocument.MailEnvelope.item .subject = "My Subject" .Recipients.Add "email@example.com" End WithEnd Sub
do i leave the gaps in as above? or do they need to be neat together?
the indentation doesn't make a difference
Nothing happens at all? Can you look in the original Word document and Outlook (if it's open)?
no nothing, at the top there is a drop down menu that has General, Command Button 1, Command Button 2 and Command Button 11
What if you just test it by clicking "Run" from the Visual Basic Editor?
Where is "run"
can u call me?
I can't unfortunately. I have some code that can easily attach a hard coded file name. Is the document name always going to be the same?
I don't understand what you mean, it has started to work but without the email address included even though I have added it to the code
I mean I have code that will generate a new email with the subject line, and will attach C:\mydocument.doc
rather than the active document
I can generate the new email, I just need the Send to email address included
yes, it's just much different to interface with Outlook once it's already opened, so you can't easily just add the email address the way you're doing it
so what do I do?
Is it acceptable to use code like this?
Private Sub CommandButton1_Click()Dim outlookapp As ObjectDim item As ObjectDim subject As StringDim msg As String Set outlookapp = CreateObject("outlook.application") msg = "Enter Message here" subject = "Enter subject here" Set item = outlookapp.CreateItem(0) With item .To = "firstname.lastname@example.org <mailtoXXX@XXXXXX.XXX>" .subject = subject .Body = msg .Display .Attachments.Add "C:\doc1.doc" End With End Sub
That will work, but notice the .Attachments.Add line towards the end
that just brings up the email with the attachments
That will attach the document you specify on that line
do I just type in there the exact name of the doc? do I include spaces?
you need to put the whole path to the document
for example, C:\documents\october\test1.doc
how do I find that?
where do you save your document to?
ok, and what is the document name?
Final Word Processing Instruction Form.docm
and what is the username you log in to the computer as?
and which version of Windows are you using?
my email address
if you save to the desktop, the path would be like this: "
C:\Users\Ben\Desktop\Final Word Processing Instruction Form.doc"
but you change "Ben" do the name you use
you might want to go to Start and type C:\Users
to see what your folder would be called
ok will try
yes that worked, thankyou, however I need the client to be able to change the form on a daily basis and for the form to be sent as per the form changes (i.e. it has drop down menu's etc) will that happen - I will give it a try
Yes, it will always attach the latest version of the document
I will try it now
Just make sure you save your document after making the changes, before sending
great! What about when the client saves this document to their desktop will the script need altering? This doc needs to live on their desktop so to send me the request form each day
Yes, so if someone else is sending it, they need to modify the same path you did to reflect their user name
Or you can do it for them if they're the only one using the script
so i should keep my email address in there as to the place it is to be sent to, but walk them through the scrip process to change the document path to their document location?
is there anyway around this?
You can even just ask them what their user name is XXXXX XXXXX the script for them, before sending it to them for the first time
that way they don't have to modify the script themselves
But yes, keep your email in there
ok so say you are the client, basically all I need to ask is:
what is your username when you log on to your computer i.e. joe.bloggs?
are you on windows 7 or xp?
what if they say XP?
I am on Windows 7
If they say XP, it will be like this:
Windows 7: C:\Users\Jog.Bloggs\Desktop\Final Word Processing Instruction Form.doc"
Windows XP: "
C:\Documents and Settings\Joe.Bloggs\Desktop\Final Word Processing Instruction Form.doc"
So that is all I need to ask them and I can change the script for them?
thank you so very much, will it work even when I have outlook on?
yes, it will
and thank you!
I hope this answers your question. Please rate me "OK Service" or higher if you are satisfied with my response, otherwise please reply and let me know how I can assist you further. Thanks again!
thanks so much again
Do you want a bonus? Happily do so if you can answer a question, when saved to other desktops with script amended (which works fine) it doesn't send the latest version, in fact it keeps asking them to save again on to desktop when they hit the save button (and then doesn't allow them to save) whereas on mine it just saves without any problem! Please can you help - desperate!?
Thanks for this, so if I change the coding to that, I don;t therefore need to change the coding for them when I save it to their desktops - is that what you mean? Sorry if I am dence, I am using VB for the first time and as you can see I am not very good!
Attachments are only available to registered users.
I pasted in the code and nothing is happening, do I only need to amend the email? or do I need to amend anything else?
It says ambigous name detetected "GetDeskTopFolder"
Private Sub CommandButton1_Click()
Dim outlookapp As Object Dim item As Object Dim subject As String Dim msg As String
Set outlookapp = CreateObject("outlook.application") Instruction Form.doc" msg = "Please can you kindly process my request and let me know as soon as possible regarding capacity" subject = "NWR Request Form" Set item = outlookapp.CreateItem(0) With item .To = "XXXXX@XXXXXX.XXX" .subject = subject .Body = msg .Display .Attachments.Add GetDesktopFolder & Application.PathSeparator & "Final Word Processing Instruction Form.docm" End With
Function GetDesktopFolder() Dim objShell Set objShell = CreateObject("WScript.Shell") GetDesktopFolder = objShell.SpecialFolders("Desktop") Set objShell = Nothing End Function
sorry, what is that?
it's is just downloading, is it something for me to paste in instead of the above, going to start crying in a mo
it's just a blank page?
the word doc was blank.
where do I find the code in the word doc?
got the code pasted it in - changed email - still nothing.
still not working - is this the code of your doc
Set outlookapp = CreateObject("outlook.application") msg = "Enter Message here" subject = "Enter subject here" Set item = outlookapp.CreateItem(0) With item .To = "XXXXX@XXXXXX.XXX <mailto:XXXXX@XXXXXX.XXX>" .subject = subject .Body = msg .Display .Attachments.Add GetDesktopFolder & Application.PathSeparator & "Final Word Processing Instruction Form.doc" End With
just nothing happens, the one you sent yesterday worked fantastic, my only problem was it that when my colleague (whom I am testing it on) amended the form from her desktop - it did eveything it was suppose to do but didnt send me the latest version (it didn't save their amendments) and when they click save it asks them to save as new but then doesn't allow them to do that either...
They click the button to email and that function works, it is just if they click save beforehand (which they need to do to send the latest version) it prompts them to save as new - how do I check if read only?
sorry ben its just not working, going to see if I can revert back to what you showed me yesterday and figure out if they can save without it being prompted to save as all the time