Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-09-2018, 11:50 PM
stu_c stu_c is offline VBA Code For Submit Button Windows 8 VBA Code For Submit Button Office 2013
Novice
VBA Code For Submit Button
 
Join Date: Dec 2013
Posts: 12
stu_c is on a distinguished road
Default VBA Code For Submit Button

Hi all
I have got a submit button on my word document that once clicked sends to a specific Email, is it possible that once clicked the button disappears and shows Form Submitted?

my current code is.



Code:
Private Sub SubmitButton1_Click()
Label1.Visible = True
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 = "Form submited"
    .Body = ""
    .To = "none@none.com"
    .Importance = olImportanceNormal
    .Attachments.Add Doc.FullName
    .Send
End With
 
Application.ScreenUpdating = True
 
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
Reply With Quote
  #2  
Old 09-10-2018, 02:00 AM
gmayor's Avatar
gmayor gmayor is offline VBA Code For Submit Button Windows 10 VBA Code For Submit Button Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Personally I would add a ribbon tab to the document to hold the submit button, however the following will disable and change the caption on the submit button.



Code:
Private Sub SubmitButton1_Click()
'Label1.Visible = True
Dim OL              As Object
Dim EmailItem       As Object
Dim Doc             As Document
 
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(0)
Set Doc = ActiveDocument
SubmitButton1.Enabled = False
SubmitButton1.Caption = "Form submitted"
Doc.Save
 
With EmailItem
    .Subject = "Form submitted"
    .Body = ""
    .To = "none@none.com"
    .Importance = 1
    .Attachments.Add Doc.FullName
    .Send
End With
 
Application.ScreenUpdating = True
 
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 09-10-2018, 02:36 AM
stu_c stu_c is offline VBA Code For Submit Button Windows 8 VBA Code For Submit Button Office 2013
Novice
VBA Code For Submit Button
 
Join Date: Dec 2013
Posts: 12
stu_c is on a distinguished road
Default

Hello mate
How would you make a submit button in a ribbon tab? I have never done one before

Quote:
Originally Posted by gmayor View Post
Personally I would add a ribbon tab to the document to hold the submit button, however the following will disable and change the caption on the submit button.



Code:
Private Sub SubmitButton1_Click()
'Label1.Visible = True
Dim OL              As Object
Dim EmailItem       As Object
Dim Doc             As Document
 
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(0)
Set Doc = ActiveDocument
SubmitButton1.Enabled = False
SubmitButton1.Caption = "Form submitted"
Doc.Save
 
With EmailItem
    .Subject = "Form submitted"
    .Body = ""
    .To = "none@none.com"
    .Importance = 1
    .Attachments.Add Doc.FullName
    .Send
End With
 
Application.ScreenUpdating = True
 
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
Reply With Quote
  #4  
Old 09-10-2018, 04:37 AM
gmayor's Avatar
gmayor gmayor is offline VBA Code For Submit Button Windows 10 VBA Code For Submit Button Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Start with http://gregmaxey.mvps.org/word_tip_p...bbon_main.html which explains the basics of ribbon editing, then see how the ribbon and code are used in the attached - or simply replace the text in the attached with your form.
Attached Files
File Type: docm Example.docm (33.9 KB, 19 views)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Code For Submit Button Submit Button Req that populates email address phorsley Word VBA 1 10-17-2017 04:50 PM
VBA Code For Submit Button Code for column button? cloudforgiven Excel Programming 1 12-18-2016 07:42 AM
Submit to Email Command Button rob7676 Word VBA 0 08-20-2015 05:05 AM
VBA Code in a UserForm module to delete a Command Button which opens the userform Simoninparis Word VBA 2 09-21-2014 03:50 AM
VBA Code For Submit Button VBA Code for a SUBMIT button in a Word form BlueMax Word VBA 3 08-07-2013 06:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:57 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft