I have a User Access Request form that I created in Word, and have now been asked to replicate in an outlook email template. This .oft file will be placed on our website, so that when users click on the link, they will download the .oft file. When the user opens the file, an email with the User Access Request form in the body will load.
I was able to set up the bookmarks, and import the Userform from Word, and have even gotten everything to populate correctly in the email from the Userform...however I have hit a wall.
I can only get the Userform to appear when I run it from Visual Basic in the Developer tab.
What I am looking to do is have the Userform pop up as soon as the template is opened, and only when that specific template is opened by a user (I don't want the Userform to open if they are trying to create a new email, or when they open outlook, etc). I have tried adding a module with the Userform.show code, I have tried adding the code below into the UserForm's code as well, with no luck.
Private Sub UserForm_Activate()
UserForm1.Show
End Sub
Do you have any suggestions as to how I can get this to work properly?
Thanks in advance!
You will need your custom logic to be present on every user's PC in order for this to work. Since you have created a UserForm in your Outlook VBA project, you will need to copy that form and supporting macros to every user's Outlook VBA project.
Often it is better to develop a COM Add-in to host your logic, and deploy it using a Windows Installer package. Deploying the .otm file where the VBA is stored is not supported.
Looks like I was able to get it to work. I added the following code:
Private Sub Application_ItemLoad(ByVal Item As Object)
R1AccessRequest.Show vbModeless
End Sub
Worked beautifully... until I sent the template over to a colleague to test... Userform appears to be tied to my outlook, and didn't appear for him. We opened up VB on his laptop, and saw that the form was not present :( From what I have been able to gather online, it doesn't seem possible.
Related
I'm creating a custom form for appointments in Outlook for a project (add catering request to a meeting) - this is my first rodeo at doing this - and I'm striking out big time regardless of my intense (and failing) Google-Fu.
With a new appointment open, on the developer tab, I select "Design This Form". I go to tab "(P.2)" and build a stupid-simple, two-object form... CheckBox1 and TextBox1. In properties, TextBox1.Visible is False. Click View Code and input the following...
Private Sub CheckBox1_Click()
if CheckBox1.value=True Then
Me.TextBox1.Visible = True
Else Me.TextBox1.Visible = False
End If
End sub
I then click "Run This Form" and see/click CheckBox1 but nothing happens. If I could make this run, I might be in business. But it won't. So, I look for a work-around.
Grasping at straws, I open "Visual Basic" and basically do the same thing - create a form "UserForm1" with the same two objects and add the same code. Click the go-button and it works as expected. The TextBox1 appears and disappears with the CheckBox1 state.
As I can make the code function, I would build everything I need in the Visual Basic editor, however... Here's the problem - I have absolutely no idea how to get the form I create here into the Outlook application as a tab or button or whatever. I basically want the custom form VBA editor to be a selectable option in any Appointment.
I have watched tutorials, read doc, saw something about creating a macro - but nothing was written/stated dumbed-down enough for me to follow.
So my question: How do I get the UserForm1 that's built in VBA Editor to appear in a New Appointment when a button is clicked in Outlook?
You need to add the Click event handler for the CheckBox control, not just paste the code to your custom form.
Following the June 13 2017 security update, users discovered published custom forms no longer worked because VBScript behind the form and some controls are blocked by default. See Custom Form Security Changes and Custom form script is now disabled by default for more information.
Microsoft disabled custom form script functionality. If you need it enabled, you'll need to set two keys, one to enable scripting and a second one with the message class name of each form that has code behind it. For example:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\16.0\Outlook\Security
DWORD: DisableCustomFormItemScript
Value: 0 (to enable)
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\16.0\Outlook\Forms\TrustedFormScriptList
REG_SZ: IPM.Contact.custom-form-name
Value: (leave blank)
In some cases, forms in secondary mailboxes and Public folders still don't work after the registry key settings. To fix this, enable scripts in the Trust Center:
Click File > Options. Then select Trust Center > Trust Center Settings > Email Security.
Under the Script in Folders section, click the checkbox for Allow script in shared folders and Allow script in Public folders and click OK and OK again to close out the windows.
I think I am facing the same problem asked by Gaus Shaikh in the link below but I have the feeling he was not understood at that time. I try to spend some other words on this topic to help you guys for your support.
I create another question because, in my opinion Gaus question title could be misunderstood.
To recap, we have a problem dealing with an excel macro that generate a user form. Actually, if the VBA project is protected by password the macro works. The weird point is that, if I just hide the code (Visual Basic Editor-> VBA project properties -> protection -> lock project from viewing -> insert pw -> OK), the macro won't works even if the project is not protected by password.
I'm stuck here. I am not able to find a solution. Have you guys have any idea?
(I am using excel 2013)
Thank you in advance!
Gaus Shaikh question:
VBA password protected project not opening userform
N.B:
Basically, any macro which generates a user form gives " run-time error 50289. Project is protected." As an example, the following macro that generate an empty user form fails if the code is hidden and works if the code is shown.
Public Sub goUserForm()
Dim mainframe As Object
'Set main frame
Set mainframe = ThisWorkbook.VBProject.VBComponents.Add(3)
'Show the form
VBA.UserForms.Add(mainframe.Name).Show
End Sub
To fully understand the issue, try this macro on your worksheet, then hide your code. Save, close and open the document. The macro won't work unless you show your code.
Ok, now it's clearer. As the VBA project is protected you will not be able to access it even not with code. Any other code will work.
So, this will not work
Set mainframe = ThisWorkbook.VBProject.VBComponents.Add(3)
VBA.UserForms.Add(mainframe.Name).Show
Code not accessing the VBA project like this will work
UserForm2.Hide
UserForm1.Show
For some users of an excel workbook, a login form that is activated on workbook_open appears behind the Internet Explorer 11 window that they use to access the workbook. (Yes, the user has either made this a trusted document or thier security settings in excel automatically enable macros)
I am unable to replicate the problem myself but have seen it occur via screen sharing.
I have tried the workbook.activate and setfocus methods but this doesn't help the users in question. Best case scenario may be to automatically minimise IE from the workbook when the form is activated (if this is possible).
Is there a fool-proof way to ensure that the excel workbook, and specifically the login form, is visible when the user opens the application via IE?
My code as it stands is ludicrously simple having removed failed attempts to remedy the problem:
Private Sub Workbook_Open()
frmLogin.Show
End Sub
I have not asked many questions on this site. Please let me know if more information is required.
I have multiple files with the same VBA code in them, which will most likely have to be changed over time. I don't want to go one by one and c/p the code, so one obvious idea that came to mind is to have one centralized document with the code (template?) that all files refer to.
I found a few topics here at stackoverflow, but none of them work for me or are inconclusive:
Run external vba-code in MS Word
Centralized VBA code (one file) for multiple workbooks
Calling an External VBA from VBScript
Any ideas?
Yes, your idea of centralizing the code in a template and attaching that template to the various Word docs will work. These pics are using Word 2007 but I think it's pretty similar for newer versions. First create a new document and put the code in a Module (named "CommonFunctions" in the picture):
Save the doc as a macro-enabled template:
Now make a new document, save it as a *.docm (necessary for it to run code because a *.docx is macro-free), and attach the document template as shown below. (An alternative is to put the *.dotm file in the startup directory C:\Users\<username>\AppData\Roaming\Microsoft\Word\STARTUP, which loads it automatically.) If you don't put it in the Startup, you'll see the name but it won't be loaded (ie, checked), but you can load it in code, as I'll show.
Make a user form in this document:
Put this code for the button's click event:
If AddIns("c:\_b\MasterDocWithFunctions.dotm").Installed = False Then
AddIns("c:\_b\MasterDocWithFunctions.dotm").Installed = True
End If
Application.Run "CommonFunctions.Test1"
Application.Run "CommonFunctions.Test2"
Notice how the code can load the AddIn for you, because it won't be automatically loaded unless you put it in the Startup directory. This pic shows how the AddIn is referenced but not loaded. You need the checkbox to be able to call code in it. If you don't load it using code and don't put it in the Startup, then the user will have to manually put a checkmark everytime the document opens.
Now the form should work when you click the button. Notice how it can call both public and private functions. The Private keyword definitely shields one module from another, but it seems like modules that are called from an AddIn are considered to be part of the same module, not sure why? Also if you don't put Public or Private at all then VBA considers it Public, I'm pretty sure.
I have written a form based document generation macro (in VBA) for distribution to a sales team.
For their ease of use, I want to provide a self-contained file which will display the form as soon as the document is opened.
Using AutoOpen I can get the form to display as intended if word is already open and the dotm file is opened within. However, if I double click the file from within explorer, nothing happens and I have to launch the macro manually. I thought AutoExec might allow this but no luck there. I've spent considerable time trying to get this to work through googling etc. but I'm not getting anywhere.
How can I make the form display even when the file is opened with a double click? Is it possible to do this without having to change normal.dotm for each user?
For further background, I am using Word 2013 with macros fully enabled during testing. The dotm file is stored in a trusted location.
I am using a macro to launch the form like this...
Public Sub AutoOpen()
StartPage.Show
End Sub
I have tried using AutoExec as well to no avail.
In the "generator.dotm" file got to Visual Basic and go in to the "ThisDocument" Microsoft Word Object.
At the top of the Visual Basic Editor select "Document" in the left hand side and then click on "New" on the right hand side. Private Sub Document_New() method will appear for you to be able to edit. Then you can call your userform in there. Similar to:
Private Sub Document_New()
Dim myForm As UserForm1
Set myForm = New UserForm1
myForm.Show
End Sub
Save your Generator.dotm and double click it through Windows explorer and you should get the results that you would like.