i use high security setting and self sign my own projects.
the program code is below. it didnt start until i added
the statement to get the name of who the mail item is
going to.
Is there a work around? I really need to try to get this
thing working right fast.
thanks for your consideration.
___________________________________________________________
Option Explicit
Dim OutItem As Outlook.MailItem
Dim OutApp As Outlook.Application
Dim objText As Object
Dim varText As Object
Dim inpText As Object
Dim bolStarted As Boolean
Dim bolItem As Boolean
Dim bolFile As Boolean
Private Sub boxLetters_Click()
' variable to hold selected option and the file name
Dim intMenu As Integer
Dim strFile As String
Dim strLtrName As String
intMenu = boxLetters.ListIndex
If intMenu < 0 Or intMenu > (boxLetters.ListCount) - 1 Then
Beep
MsgBox "Please select Letter to write",
vbOKOnly, "Error"
End If
Select Case intMenu
Case Is = 0
strFile = "J1 Visa Program General
Information.htm"
Case Is = 1
strFile = "J1 Seafood Processing Program
General Information.htm"
Case Is = 2
strFile = "J1 Seafood Processing Program
Specific Information.htm"
Case Is = 3
strFile = ""
Case Is = 4
strFile = ""
Case Is = 5
strFile = ""
Case Is = 6
strFile = ""
Case Is = 7
strFile = ""
Case Is = 8
strFile = ""
Case Is = 9
strFile = ""
Case Is = 10
strFile = "J1SeafoodGeneral.htm"
Case Is = 11
strFile = "J1E-mailresponse_Html.htm"
Case Is = 12
strFile = ""
Case Else
Beep
MsgBox "Programmer Error", vbOKOnly, "Error"
End Select
strLtrName = boxLetters.Text
Create_Response strFile, strLtrName
End
End Sub
Private Sub UserForm_Initialize()
' Build the letter pick list
' general program info
boxLetters.AddItem "Agent: J1 General Program", 0
' seafood processing drilling down
boxLetters.AddItem "Agent: J1 Seafood General Program", 1
boxLetters.AddItem "Agent: J1 Seafood Specific Program", 2
' resort drilling down
boxLetters.AddItem "Agent: J1 Resort General Program", 3
boxLetters.AddItem "Agent: J1 Resort Specific Program", 4
' general program info
boxLetters.AddItem "Agent: H2b General Program Program", 5
' seafood processing drilling down
boxLetters.AddItem "Agent: H2b Seafood General Program", 6
boxLetters.AddItem "Agent: H2b Seafood Specific Program", 7
' resort drilling down
boxLetters.AddItem "Agent: J1 Resort General Program", 8
boxLetters.AddItem "Agent: J1 Resort Specific Program", 9
' add applicant letters
' j1- first
boxLetters.AddItem "J1: Seafood General Program", 10
boxLetters.AddItem "J1: Seafood Specific Program", 11
' h2b first contact
boxLetters.AddItem "H2b: Program Introductory", 12
' give user look down message
boxLetters.Text = "Please Scroll Down and Pick Letter to
Send"
End Sub
Private Sub UserForm_Terminate()
If bolItem = True Then
Set OutItem = Nothing
End If
If bolStarted = True Then
Set OutApp = Nothing
End If
If bolFile = True Then
Set inpText = Nothing
Set varText = Nothing
Set objText = Nothing
End If
End
End Sub
Sub Create_Response(strName As String, Strletter As String)
Dim strSubject As String
Dim strBody As String
Dim strFromName As String
On Error Resume Next
' outlook mail client
Set OutApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set OutApp = CreateObject("Outlook.Application")
bolStarted = True
End If
' get currently opened email to reply to
Set OutItem = OutApp.ActiveInspector.CurrentItem
If Err <> 0 Then
' not on item for reply
Beep
MsgBox "You must select an email to reply to",
vbOKOnly, "Error"
UserForm_Terminate
Exit Sub
Else
bolItem = True
End If
If OutItem.Sent = True Then
' not in reply mode on that item
Beep
MsgBox "You must be in reply mode!", vbOKOnly, "Error"
UserForm_Terminate
Exit Sub
Else
bolItem = True
End If
'now comes the tricky part
Set objText = CreateObject("Scripting.FileSystemObject")
If Err <> 0 Then
'system error unable to create file system object
Beep
MsgBox "unable to create File System Object: " & Str
(Err), vbCritical, "SYSTEM ERROR"
UserForm_Terminate
Exit Sub
End If
Set varText = objText.getfile("C:\My Documents\H2B
Coordinator\LetterTexts\" & strName)
If Err <> 0 Then
'programmer error file not found
Beep
MsgBox "Unable to Locate " & strName,
vbCritical, "SYSTEM ERROR"
Set objText = Nothing
UserForm_Terminate
Exit Sub
End If
Set inpText = varText.openastextstream(1, -2)
If Err <> 0 Then
'programmer error file not found
Beep
MsgBox "Unable to read " & strName,
vbCritical, "SYSTEM ERROR"
Set objText = Nothing
Set varText = Nothing
UserForm_Terminate
Exit Sub
Else
bolFile = True
End If
strBody = inpText.readall
inpText.Close
' get the name of who to send it to from address header
strFromName = OutItem.To
' build email subject line
strSubject = "Here is the " _
& Right(Strletter, (Len(Strletter) - (InStr(1,
Strletter, ":") + 1))) _
& " Information You Requested"
'find generic applicant text and replace it with name
If InStr(1, strBody, "[STUDENT]") > 0 Then
strBody = Address_Email(strFromName,
strBody, "[STUDENT]")
End If
'find generic agent text and replace it with name
If InStr(1, strBody, "[AGENT]") > 0 Then
strBody = Address_Email(strFromName,
strBody, "[AGENT]")
End If
' set up the reply and display it
With OutItem
.Reply
'Set the subject
.Subject = strSubject
'The content of the document is used as the body for
the email
.BodyFormat = olFormatHTML
.HTMLBody = strBody
.Display
End With
End Sub
Function Address_Email(strName As String, StrInput As
String, strReplace As String)
Dim dblBgn As Double
Dim dblEnd As Double
Dim dblLen As Double
Dim dblStr As Double
Dim str1st As String
Dim strLst As String
dblStr = InStr(1, StrInput, strReplace)
str1st = Left(StrInput, (dblStr - 1)) & StrConv((Trim
(strName)), vbProperCase)
dblBgn = dblStr + Len(strReplace)
dblLen = Len(StrInput)
dblEnd = dblLen - dblBgn
strLst = Right(StrInput, dblEnd)
Address_Email = str1st & strLst
End Function
This statement is subject to Outlook security prompts, which pop up when an application tries to access certain Outlook properties and methods are designed to inhibit the spread of viruses via Outlook; see http://www.slipstick.com/outlook/esecup.htm#autosec. If you are a standalone user, Outlook provides no way to suppress this behavior. However, you can use a free tool called Express ClickYes (http://www.express-soft.com/mailmate/clickyes.html) to click the security dialog buttons automatically. Beware that this means if a virus tries to send mail using Outlook or gain access to your address book, it will succeed.
If you're the administrator in an Exchange Server environment, you can reduce the impact of the security prompts with administrative tools. See http://www.slipstick.com/outlook/esecup/admin.htm
If it's an application you wrote yourself, you can use one of these approaches to redo the program:
-- Use Extended MAPI (see http://www.slipstick.com/dev/mapi.htm) and C++ or Delphi; this is the most secure method and the only one that Microsoft recommendeds.
-- Use Redemption (http://www.dimastr.com/redemption/), a third-party COM library that wraps around Extended MAPI but parallels the Outlook Object Model
-- Use SendKeys to "click" the buttons on the security dialogs that your application may trigger. See http://www.slipstick.com/outlook/esecup.htm#autosec for a link to sample code.
-- Program the free Express ClickYes (http://www.express-soft.com/mailmate/clickyes.html) tool to start suspended and turn it on only when your program needs to have the buttons clicked automatically.
"woody" <woody...@pacific.net.id> wrote in message news:0e3a01c31f8f$6b933620$a101...@phx.gbl...
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
1) i hate c with a serious passion
2) tons of vbcode alreayd i use here by me.
im a small startup company, i run the head overseas office, coordinate 7
countries, 43 agents, etc etc.... no staff here except me. I need
automation to live!
i love developing but not much time so i stick with what im good at.