Re: Open User Form from Template and populate message



My turn to be confused. Did exactly as requested. From Outlook pressed
Alt+F11 it opened Project1(VbaProject.OTM) with the exact code listed below.

I do not have the tools to work in VBS, so I am working in VBA.

The "limitations" that I am speaking about is that in other Microsoft Office
products I can tie code to the document I am working on (i.e. I can have
different code for one Word template to the next, same for Excel, and of
course for Access) that only affects that document, but Outlook does not seem
to function the same way. Therefore I believe, maybe incorrectly, that
Outlook is more limited than the previously listed Microsoft products.

Jason

"Michael Bauer" wrote:

> Wow, I begin to feel like someone in the German TV Show "Hidden
> camera"... Anyway, I try it again .-)
>
>
> > The Template named TSG Dispatch.oft has the following VBA code
> attached to it:
> > <Microsoft Outlook Objects>
> > <This Outlook Session>
>
> The code behind an *.oft template isn´t VBA, but VBS. And what I gave to
> you is VBA. That means, it isn´t working in VBS, i.e. also isn´t
> working behind an *.oft template.
>
> Please open the VBA environment (ALT+F11) and display the Project
> Explorer (STRG+R). The modul "ThisOutlookSession" belongs already to the
> project. This is the modul where the code needs to be which I have
> included in the <ThisOutlookSession> tags. To this project you can add
> the additional standard modul with the Const declarations.
>
> To clarify that: It could be perfectly possible that there is also a way
> for just using VBS behind the template without any VBA - but I don´t
> know that. If you want to try that VBS way then, please, throw my sample
> away and forget it - believe me, it won´t work and that´s not a point of
> any security settings.
>
> BTW: What "limitations" you´re talking about?
>
> --
> Viele Grüße / Best regards
> Michael Bauer - MVP Outlook
>
>
> "Tahlmorrah" <Tahlmorrah@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:2178A7B0-B204-427B-BDAB-139EFEA22797@xxxxxxxxxxxxxxxx
> > Thank you for letting me know that I had to have those items in
> > ThisOutlookSession. I do not consider that secure at all, but we can
> only
> > work within the limitations Microsoft has given us.
> >
> > The Template named TSG Dispatch.oft has the following VBA code
> attached to it:
> > <Microsoft Outlook Objects>
> > <This Outlook Session>
> >
> > Option Explicit
> > Private WithEvents Inspectors As Outlook.Inspectors
> >
> > Private Sub Application_Startup()
> > Set Inspectors = Application.Inspectors
> > End Sub
> >
> > Private Sub Inspectors_NewInspector(ByVal Inspector As
> Outlook.Inspector)
> > If Inspector.CurrentItem.Subject = TEMPLATE_SUBJECT Then
> > TSGRequest.Show 1
> > End If
> > End Sub
> > </This Outlook Session>
> > </Microsoft Outlook Objects>
> >
> > <Forms>
> > <TSGRequest>
> >
> > Private Sub CmdBtnSubmit_Click()
> > Set oMail = Application.ActiveInspector.CurrentItem
> >
> > ReplaceCenter = "<TxtBxCenter>"
> > ReplaceHO = "<TxtBxHO>"
> > ReplaceHC = "<TxtBxHC>"
> > ReplaceTZ = "<TxtBxTZ>"
> > ReplaceTech = "<TxtBxTech>"
> > ReplacePhone = "<TxtBxPhone>"
> > ReplaceSev = "<TxtBxSev>"
> > ReplaceReason = "<TxtBxReason>"
> > ReplaceDate = "<TxtBxDate>"
> > ReplaceIssue = "<TxtBxIssue>"
> >
> > oMail.Subject = Replace(oMail.Subject, ReplaceCenter,
> TxtBxCenter.Text)
> > oMail.Body = Replace(oMail.Body, ReplaceCenter, TxtBxCenter.Text)
> > oMail.Body = Replace(oMail.Body, ReplaceHO, TxtBxHO.Text)
> > oMail.Body = Replace(oMail.Body, ReplaceHC, TxtBxHC.Text)
> > oMail.Body = Replace(oMail.Body, ReplaceTZ, TxtBxTZ.Text)
> > oMail.Body = Replace(oMail.Body, ReplaceTech, TxtBxTech.Text)
> > oMail.Body = Replace(oMail.Body, ReplacePhone, TxtBxPhone.Text)
> > oMail.Body = Replace(oMail.Body, ReplaceSev, TxtBxSev.Text)
> > oMail.Body = Replace(oMail.Body, ReplaceReason, TxtBxReason.Text)
> > oMail.Body = Replace(oMail.Body, ReplaceDate, TxtBxDate.Text)
> > oMail.Body = Replace(oMail.Body, ReplaceIssue, TxtBxIssue.Text)
> >
> > Unload TSGRequest
> > End Sub
> >
> > Private Sub CmdBtnClear_Click()
> > TxtBxCenter = ""
> > TxtBxHO = ""
> > TxtBxHC = ""
> > TxtBxTZ = ""
> > TxtBxTech = ""
> > TxtBxPhone = ""
> > TxtBxSev = ""
> > TxtBxReason = ""
> > TxtBxDate = ""
> > TxtBxIssue = ""
> > End Sub
> >
> > Private Sub TSGRequest_Activate()
> > TxtBxDate.Text = DateAdd("d", 1, Date)
> >
> > End Sub
> >
> > </TSGRequest>
> > </Forms>
> >
> > <Modules>
> > <Module1>
> >
> > Public Const TEMPLATE_SUBJECT As String = "TSG Dispatch Center
> <TxtBxCenter>"
> > Public Const REPLACE_SUBJECT As String = "<TxtBxCenter>"
> >
> > </Module1>
> > </Modules>
> >
> > Problem: Userform:TSGRequest does not automatically open when template
> TSG
> > Dispatch.oft is opened. Pretty sure I need a load or activate command
> > referancing userform:TSGRequest somewhere in the code so that when
> the .oft
> > is opened it pops up, but I am unsure of the command or where it
> should be
> > placed.
> >
> > Believe or not this has been helpful. I get bits and pieces here and
> there
> > that help improve my knowledge of VBA and how it relates to Outlook,
> and as
> > you can see parts that help improve my code.
> >
> > Jason
> >
> >
> > "Michael Bauer" wrote:
> >
> > > Hi Jason,
> > >
> > > sorry, I understand less and less. The sample I´ve given to you must
> be
> > > executed in VBA, modul "ThisOutlookSession". You can´t move this
> code
> > > into your *.oft template.
> > >
> > > Whether you´re using VBScript in your template or not, because
> you´re
> > > also using an UserForm you have to enable VBA anyway.
> > >
> > > Or do you mean your *.oft template when talking about an UserForm?
> If so
> > > then it seems that you´d need help for VBScript, not VBA. That´s not
> my
> > > area.
> > >
> > > (IMHO VBA is more secure than using scripting in an template. It´s
> not
> > > easy to change or manipulate the project file (*.otm) - but very
> easy to
> > > change your *.oft file.)
> > >
> > > --
> > > Viele Grüße / Best regards
> > > Michael Bauer - MVP Outlook
> > >
> > >
> > > "Tahlmorrah" <Tahlmorrah@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> > > news:C1D9843D-59B1-4579-A144-BAF1300FEE30@xxxxxxxxxxxxxxxx
> > > > > Not sure, what you´re saying.
> > > >
> > > > I do not care that my security settings ask me to enable macros.
> This
> > > is
> > > > working as intended. I only want it to prompt when this .oft is
> opened
> > > as it
> > > > is more secure. It appears that I need to add something that is
> local
> > > to the
> > > > .oft rather than ThisOutlookSession. I only used
> ThisOutlookSession as
> > > I do
> > > > not know how to accomplish this so it is only contained in the
> ..oft.
> > > >
> > > > All security settings are Custom based off of the Medium setting.
> > > >
> > > > The intention is to make a self contained macro in the template
> that
> > > only
> > > > activates when the template opens. Having macros that activate
> when
> > > Outlook
> > > > opens is not an option due to it compromising system security.
> > > >
> > > > Here is the desired sequence of events:
> > > > 1. User opens Outlook and works on it throughout the day
> > > > 2. User has need of template and opens template by clicking on the
> > > ..oft file
> > > > 3. Prompted to enable macros in the .oft
> > > > 4. Userform is displayed
> > > > 5. Completes userform and Submits
> > > > 6. Text on Template is changed with the entered information
> > > > 7. User can make additional changes as necessary
> > > > 8. E-mail is sent
> > > > 9. User continues to use Outlook as normal
> > > > 10. User has need of template and opens template
> > > > 11. See step 3.
> > > >
> > > > > This is not what I´ve suggested.
> > > > I understand that is not what you have suggested, but this is the
> only
> > > way I
> > > > have been able to get the userform to even show. If you can tell
> me
> > > how to
> > > > get the userform to show when the template opens, I will be more
> than
> > > glad to
> > > > change the code. This is my primary problem at this time.
> > > >
> > > > Jason
> > > >
> > > > "Michael Bauer" wrote:
> > > >
> > > > > > Started to get promted for macros after Outlook after closed
> and
> > > > > reopen
> > > > > > Outlook. If open template at that point, prompts for macros
> and
> > > opens
> > > > > > userform when changed
> > > > >
> > > > > Not sure, what you´re saying.
> > > > >
> > > > > As I mentioned earlier, you need to restart OL after making
> changes
> > > to
> > > > > the code or run Application_Startup manually. The execution of
> this
> > > > > function is important. If it´s done once and you don´t make more
> > > changes
> > > > > to the code then OL can stay opened till the end of the days.
> > > > >
> > > > > > Private Sub Application_Startup()
> > > > > > Set Inspectors = Application.Inspectors
> > > > > > TSGRequest.Show 1
> > > > >
> > > > > This is not what I´ve suggested.
> > > > >
> > > > > --
> > > > > Viele Grüße / Best regards
> > > > > Michael Bauer - MVP Outlook
> > > > >
> > > > >
> > > > > "Tahlmorrah" <Tahlmorrah@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
> message
> > > > > news:97784E51-2A21-454D-AEB2-8C402C9910BB@xxxxxxxxxxxxxxxx
> > > > > > Started to get promted for macros after Outlook after closed
> and
> > > > > reopen
> > > > > > Outlook. If open template at that point, prompts for macros
> and
> > > opens
> > > > > > userform when changed
> > > > > >
> > > > > > <ThisOutlookSession>
> > > > > > Private Sub Application_Startup()
> > > > > > Set Inspectors = Application.Inspectors
> > > > > > TSGRequest.Show 1
> > > > > > End Sub
> > > > > > </ThisOutlookSession>
> > > > > >
> > > > > > However this is not accomplishing what I need to. Users need
> to
> > > keep
> > > > > Outlook
> > > > > > open at all times. When this template is selected they need
> the
> > > > > userform to
> > > > > > open automatically on top of the template.
> > > > > >
> > > > > > Progress is slow, but its progress
> > > > > > Thanks again
> > > > > > Jason
> > > > > >
> > > > > >
> > > > > > "Tahlmorrah" wrote:
> > > > > >
> > > > > > > Never hitting the breakpoint even with Outlook closed.
> > > > > > >
> > > > > > > Jason
> > > > > > >
.