Outlook 365 command button in outlook form

Status
Not open for further replies.

bdsermons

Member
Outlook version
Outlook 365 64 bit
Email Account
Exchange Server
I am creating an Outlook form where clients can submit a request to review documents that they can select by clicking on a command button (a picture of a file folder) which will open a file dialog box and let them choose the file they want to insert into the form.

I have created the macro for the CommandButton2_click but I am having trouble applying the code to the CommandButton in the Outlook form.

The Code that I am using is below.


Here is the code in VBA:
(Name of the Macro is Attach1)


Public Sub CommandButton2_Click()
Dim XL As Object
Dim strTest As String
Set XL = CreateObject("Excel.Application")
strTest = XL.GetOpenFilename()

End Sub


Code behind form command button:​

(I know it needs to look something like this....)

Sub CommandButton2_Click()
Call macro-name()

End Sub
----------------------------
Sub macro-name()
' not sure what should go here

End Sub
 
Are you sending this to the internet? It won't work - the macro and script will not be sent. It would only work in an exchange environment where you publish the form to the org forms library.

You want to use the excel file explorer macro in the code in the form? Or are you trying to call that code from the command button?
 
1. I am not sending this to the internet. I just want my colleagues to use the form from their independent desktops.

2. I am wanting to call this code from the command button.

Thank you so much for all your help.
 
BTW - does any of your code work? you need to set a reg key to run scripts -
 
This is working for me - but the open dialog is coming up behind my form. (The date stamp is so I know its working)

Code:
Sub GetFile()
Item.Body = Now() & vbCrLf & vbCrLf & Item.Body
'Dim XL As Object
'Dim strTest As String
Set XL = CreateObject("Excel.Application")
strTest = XL.GetOpenFilename()
item.attachments.add strTest
End Sub

Sub CommandButton1_Click()
  Call GetFile()
End Sub

1650512193212.png
 
This is working for me - but the open dialog is coming up behind my form. (The date stamp is so I know its working)

Code:
Sub GetFile()
Item.Body = Now() & vbCrLf & vbCrLf & Item.Body
'Dim XL As Object
'Dim strTest As String
Set XL = CreateObject("Excel.Application")
strTest = XL.GetOpenFilename()
item.attachments.add strTest
End Sub

Sub CommandButton1_Click()
  Call GetFile()
End Sub

View attachment 3579
Hi Dianne, apologies I'm new to this forum and can't seem to find the correct space to add a new question.
I'm successfully able to add a VBA code to my custom form command button, but it does not seem to work. I created a button with the same code in the custom ribbon and it's working so not sure what i'm doing wrong.

I'm very new to this so please excuse the silly question.

Your assistance would be greatly appreciated.

Monica
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J Command Button to stamp a date and time in a textbox in Outlook 2016 Outlook VBA and Custom Forms 3
M Open new outlook form from within existing outlook form using command button Using Outlook 4
M VbScript for Command Button on Contacts Custom Form Using Outlook 1
D Command Button code will not execute. Any suggestions Please. Outlook VBA and Custom Forms 2
S Problem running Command button code Outlook VBA and Custom Forms 2
S Code behind form command button Using Outlook 2
A Command Button Controls Outlook VBA and Custom Forms 6
J Command Button to insert Email Signature Outlook VBA and Custom Forms 2
Z Command button no longer firing after sending custom form over ema Outlook VBA and Custom Forms 1
U Customized Command Button Outlook VBA and Custom Forms 3
M Move command Outlook VBA and Custom Forms 11
S Command Button_Click action on Item/Reminder Outlook VBA and Custom Forms 3
J OUTLOOK 2016 FILE STORAGE WHERE COMMAND Using Outlook 12
D Custom Form Accept and Reject Command buttons Outlook VBA and Custom Forms 2
Dr. Demento Outlook version of Excel command? Using Outlook 5
L Outlook Data Files command not working in the quick access bar Using Outlook 1
R Missing Backup command in File menu after installing pfback.exe Using Outlook 2
S Exchange Management Shell closes on command failure Exchange Server Administration 5
M "New Appointment from Contact" command missing from Outlook 2003 Using Outlook 1
J Executing Ribbon Command from Code Outlook 2010 Outlook VBA and Custom Forms 3
S How to call a procedure from a custom command bar in Outlook 2007 Outlook VBA and Custom Forms 1
L Outlook 2003 - Set Virables via command line Outlook VBA and Custom Forms 1
T Command bar IDs for Outlook 2007 Using Outlook 2
T Is there a VBA command to Redirect your Emails? Outlook VBA and Custom Forms 1
A How to access command bars in outlook 2007 Outlook VBA and Custom Forms 3
5 How to get Outlook's command line parameters? Outlook VBA and Custom Forms 1
J Hide/Disable the X button on BrowseForFolder Dialog Using Outlook 4
B Please remind me how I added this message button Outlook VBA and Custom Forms 0
G Add Map It button to Custom Contacts Form in Outlook Outlook VBA and Custom Forms 1
J Outlook 2021 ScanPST errors (yet again ... sorry): repair button missing Outlook 2021 Using Outlook 5
S Outlook 2002- "Send" button has disappeared. Help please. Using Outlook 1
TomHuckstep Remove Send/Receive All Folders (IMAP/POP) button from Outlook 365 Ribbon Using Outlook 2
Witzker How to get the button Karte ( map) in custom contact form Outlook VBA and Custom Forms 2
J Want to create a button on the nav bar (module add-in) to run code Outlook VBA and Custom Forms 2
B How to create a button that sorts and selects the most recent message with ONE click Using Outlook 2
jehan2256 "History" button in Business Contact Manager Using Outlook 1
L "Insert Pictures" Button-Wrong Folder Using Outlook 5
O Replace hard returns with soft returns on selected text and button to QAT Using Outlook 5
J "Contact" button in Journal entry Using Outlook 1
O Outlook 2010 Add delete button to the side of the message list Using Outlook 1
I Button PDF in Outlook Contact custom form Outlook VBA and Custom Forms 1
D Outlook 2013 Macros only run in VB editor, not in drop down or button Outlook VBA and Custom Forms 14
N contact list seen in Contact folder but knot in Address book or when 'TO' button is clicked in new email Using Outlook 0
Witzker HowTo start a macro with an Button in OL contact form Outlook VBA and Custom Forms 12
R Follow up button doesn't working neither the reminders in BCM BCM (Business Contact Manager) 0
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
K Disabling import/export button to restrict PST creation Using Outlook 3
N Which Button Was Clicked on the Ribbonbar Menu Outlook VBA and Custom Forms 2
E Can't accept or decline task (no button appears) Using Outlook 2
Q Prompt button to auto turn on Out of Office Outlook VBA and Custom Forms 3

Similar threads

Back
Top