adriancd
09-01-2010, 04:59 AM
Hi All,
I am in a bit of a pickle.
I have setup a command button in a word document that users can click and it sends the document to a specified email address and closes down word automatically.
After several days of google site hopping, and failed attempts to get this thing going, I am at the point where I think I am going to go either bald or grey and I am only 24.
I have the code sorted however when I check the email attachement, the document appears blank without the user's changes. The file is subject to fields and the users are unable to edit the document apart from those fields I have created. I do not require them to save the file as I am the only one who needs the finalised version.
Here is my code:
Private Sub CommandButton1_Click()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
'You'll need to add the Outlook Object Library to VBA Tools References
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved
ActiveDocument.Save 'so save it
End If
'see if Outlook is running and if so turn your attention there
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then 'Outlook isn't running
'So fire it up
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Open a new e-mail message
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem 'and add the detail to it
.To = "adrian.dressekie" 'send to this address
.Subject = "Complimentary Ticket Request" 'This is the message subject
.Body = "Please process the attached document" ' This is the message body text
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue
.Send
'**********************************
'If you want to view the message before it goes
'change the line above from .Send to .Display
'Otherwise the message is sent straight to the Outbox
'and if you have Outlook set to send mail immediately,
'it will simply be Sent
'with no obvious sign that Outlook has operated.
'Apart from the copy in the Outlook Sent folder
'**********************************
End With
If bStarted Then 'If the macro started Outlook, stop it again.
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
Application.ScreenUpdating = False
ActiveDocument.Close wdDoNotSaveChanges
End Sub
I have activated all of the relevant references, but still no luck.
Could someone please help.
In a summary here is what I would like it to do:
User opens document (if possible as a template)
User fills in First and Last Name (in fields)
User selects (from drop down fields) the amount of tickets they require
User types their initials as digital signature (in field)
User hits submit (control toolbox command button) which then sends the completed document automatically to my mailbox and closes word without any save as dialog boxes or anything.
If the above is not possible, would I be able to have it so:
User opens document
User fills in First and Last Name
User selects the amount of tickets they require
User types their initials as digital signature
User hits submit and which then saves the document to their default document folder, sends me the document as an attachment to my mailbox and closes word down.
I am not really bothered if it saves or not, but I really need it to be dummy proof for the users and that they do not see any dialog boxes.
Also if possible to set it so that it sends an automatic email back to the user confirm receipt of the attachment and inform them their tickets will be ready within 5 working days.
I know it may seem like alot but the help will be very much appreciated.
Adrian
Edited 2-Sep-10 by geekgirlau. Reason: insert vba tags
I am in a bit of a pickle.
I have setup a command button in a word document that users can click and it sends the document to a specified email address and closes down word automatically.
After several days of google site hopping, and failed attempts to get this thing going, I am at the point where I think I am going to go either bald or grey and I am only 24.
I have the code sorted however when I check the email attachement, the document appears blank without the user's changes. The file is subject to fields and the users are unable to edit the document apart from those fields I have created. I do not require them to save the file as I am the only one who needs the finalised version.
Here is my code:
Private Sub CommandButton1_Click()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
'You'll need to add the Outlook Object Library to VBA Tools References
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved
ActiveDocument.Save 'so save it
End If
'see if Outlook is running and if so turn your attention there
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then 'Outlook isn't running
'So fire it up
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Open a new e-mail message
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem 'and add the detail to it
.To = "adrian.dressekie" 'send to this address
.Subject = "Complimentary Ticket Request" 'This is the message subject
.Body = "Please process the attached document" ' This is the message body text
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue
.Send
'**********************************
'If you want to view the message before it goes
'change the line above from .Send to .Display
'Otherwise the message is sent straight to the Outbox
'and if you have Outlook set to send mail immediately,
'it will simply be Sent
'with no obvious sign that Outlook has operated.
'Apart from the copy in the Outlook Sent folder
'**********************************
End With
If bStarted Then 'If the macro started Outlook, stop it again.
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
Application.ScreenUpdating = False
ActiveDocument.Close wdDoNotSaveChanges
End Sub
I have activated all of the relevant references, but still no luck.
Could someone please help.
In a summary here is what I would like it to do:
User opens document (if possible as a template)
User fills in First and Last Name (in fields)
User selects (from drop down fields) the amount of tickets they require
User types their initials as digital signature (in field)
User hits submit (control toolbox command button) which then sends the completed document automatically to my mailbox and closes word without any save as dialog boxes or anything.
If the above is not possible, would I be able to have it so:
User opens document
User fills in First and Last Name
User selects the amount of tickets they require
User types their initials as digital signature
User hits submit and which then saves the document to their default document folder, sends me the document as an attachment to my mailbox and closes word down.
I am not really bothered if it saves or not, but I really need it to be dummy proof for the users and that they do not see any dialog boxes.
Also if possible to set it so that it sends an automatic email back to the user confirm receipt of the attachment and inform them their tickets will be ready within 5 working days.
I know it may seem like alot but the help will be very much appreciated.
Adrian
Edited 2-Sep-10 by geekgirlau. Reason: insert vba tags