Results 1 to 1 of 1

Thread: How to Create, Open, attach and use Temporary Email Files with Outlook

Threaded View

  1. #1

    Thread Starter
    Lively Member binduau's Avatar
    Join Date
    Sep 2003
    Location
    Perth Australia
    Posts
    121

    How to Create, Open, attach and use Temporary Email Files with Outlook

    How to Create, Open, attach and use Temporary Email Files with Outlook 2000

    VB Code:
    1. sFileName = Replace(sFileName, Chr(32), "_", 1)

    'Collect the Data

    VB Code:
    1. 'If any temporary files exist or if the function or program
    2. 'crashes, the temporary files are deleted at startup also.
    3.  
    4. 'Initialize the send parameters
    5.  
    6. Private Sub mnuOsend_Click()
    7. On Error GoTo err_Attach
    8. Dim _
    9. strFname As String, _
    10. strTemp As String, _
    11. i As Integer, _
    12. strFilter As String
    13.  
    14. 'i want to kill outlook
    15. TerminateEXE "OUTLOOK.EXE"
    16.  
    17. 'get the file from the cmdialog
    18. 'i was going to use an API cmdialog but
    19. 'i can't be bothered DOH!
    20.  strFilter = "Archived Order Files (*.txt)|*.txt|" _
    21.             & "HTML Template Files (*.html)|*.html|" _
    22.             & "All Files (*.*)|*.*|" _
    23.             & "HTM Template Files(*.htm)|*.htm|" _
    24.             & "Template Files(*.tpl)|*.tpl|" _
    25.             & "Log Files(*.Log)|*.Log"
    26. 'Open the dialog
    27. strFname = Locate_OpenFile("Please Select a a File To Attach to _
    28. & " This Mail.", strFilter, DefOutPutFolder)
    29.  
    30. 'in my temporary files i put an underscore because outlook
    31. 'hates spaces in its attach command line switch
    32.  
    33. If Len(strFname) <> 0 Then
    34.     'Replace the spaces in the filename with the
    35.     'underscore character
    36.     For i = 1 To Len(strFname)
    37.         If Mid(strFname, i, 1) <> Chr(32) Then
    38.             strTemp = strTemp & Mid(strFname, i, 1)
    39.         Else
    40.             strTemp = strTemp & "_"
    41.         End If
    42.     Next i
    43.    
    44.     'Check if the file exists
    45.         If Len(Dir(strTemp)) = 0 Then
    46.             'Create a temporary file
    47.             FileCopy strFname, strTemp
    48.         Else
    49.             'if the temporary file pre-exists delete it.
    50.             Kill strTemp
    51.             'Create a NEW temporary file
    52.             FileCopy strFname, strTemp
    53.         End If
    54.        
    55.     'Open a new email  message with the file attached
    56.     Open_Out_Folder "/a " & strTemp, 1
    57.  
    58. End If
    59. Exit_Attach:
    60. Exit Sub
    61. err_Attach:
    62. MsgBox Err.Description
    63. Resume Exit_Attach
    64. End Sub


    Get the filename

    VB Code:
    1. Function Locate_OpenFile(dlgtitle As String, strFilter As String, InitDir _
    2. As String) As String
    3. On Error GoTo err_Open
    4.  'set the string value of the email reply template folder
    5.          Dim sBuf As String
    6.        
    7.         Cmdialog.Filter = strFilter
    8.         Cmdialog.InitDir = InitDir
    9.         Cmdialog.DialogTitle = dlgtitle
    10.         Cmdialog.ShowOpen
    11.              
    12.        If Len(Cmdialog.FileName) <> 0 Then
    13.                 'send the filename back
    14.             Locate_OpenFile = Cmdialog.FileName
    15.  
    16.         End If
    17. Exit_Open:
    18. Exit Function
    19. err_Open:
    20. MsgBox Err.Description
    21. Resume Exit_Open
    22.  
    23.  
    24. End Function


    'Open a New message with the attached file

    VB Code:
    1. Public Sub Open_Out_Folder(FolderToOpen As String, intview As Integer)
    2.  On Error GoTo err_Open_Out
    3.  Dim strFileName As String, wShell As Object, StrAppName As String
    4.     Screen.MousePointer = vbHourglass
    5.  
    6. 'get the path to outlook from the registry
    7.  
    8. StrAppName = GetRegStringValue$(HKEY_LOCAL_MACHINE, _
    9. "Software\Microsoft\Windows\CurrentVersion\App Paths\outlook.exe", "")
    10.  
    11. Select Case intview
    12. Case 0
    13.     'The folder name can't have a space in it
    14.     'Open The Folder
    15.      strFileName = StrAppName & " /select outlook:" & FolderToOpen
    16.    
    17. Case 1
    18. 'StickyNote Appointment Task
    19.      strFileName = StrAppName & " " & FolderToOpen
    20.  
    21. Case 2
    22. 'Send an attached file
    23.  
    24. End Select
    25.  
    26.     Shell strFileName, vbNormalFocus
    27.      Screen.MousePointer = vbDefault
    28. exit_Open_Out:
    29. Exit Sub
    30. err_Open_Out:
    31. MsgBox Err.Description
    32. Resume exit_Open_Out
    33. End Sub

    'Call this at Startup to do what you want

    VB Code:
    1. Sub loadFileList()
    2. On Error GoTo ErrorHandler
    3. 'Image1.Picture = Image2.Picture
    4. Dim SearchPath As String, FindStr As String
    5. Dim FileSize As Long
    6. Dim NumFiles As Integer, NumDirs As Integer
    7. Screen.MousePointer = vbHourglass
    8. SearchPath = DefOutPutFolder
    9. FindStr = "*.txt"
    10.  
    11. 'Locate all the files for the list.
    12. FileSize = FindFiles(SearchPath, FindStr, NumFiles, NumDirs)
    13. Exit_LoadFile:
    14. Screen.MousePointer = vbDefault
    15. Exit Sub
    16.  
    17. ErrorHandler:
    18. MsgBox Err.Description
    19. Resume Exit_LoadFile
    20. End Sub

    This is the FindFiles function called from the sub above

    VB Code:
    1. 'P.S i don't feel like indenting this at the correct places
    2.  
    3. Public Function FindFiles(path As String, SearchStr As String, _
    4. FileCount As Integer, DirCount As Integer)
    5. Dim FileName As String
    6. Dim DirName As String
    7. Dim dirNames() As String
    8. Dim nDir As Integer
    9. Dim i As Integer
    10. On Error GoTo sysFileERR
    11. If Right(path, 1) <> "\" Then path = path & "\"
    12. nDir = 0
    13. LstFilesSaved.Clear
    14. ReDim dirNames(nDir)
    15. DirName = Dir(path, vbDirectory Or vbHidden)
    16. Do While Len(DirName) > 0
    17.  
    18. If (DirName <> ".") And (DirName <> "..") Then
    19. If GetAttr(path & DirName) And vbDirectory Then
    20. dirNames(nDir) = DirName
    21. DirCount = DirCount + 1
    22. nDir = nDir + 1
    23. ReDim Preserve dirNames(nDir)
    24. End If
    25. sysFileERRCont:
    26. End If
    27. DirName = Dir()
    28. Loop
    29. FileName = Dir(path & SearchStr, vbNormal Or vbHidden Or vbSystem _
    30. Or vbReadOnly)
    31. While Len(FileName) <> 0
    32. FileCount = FileCount + 1
    33.  
    34. 'in my temporary files i put an underscore because outlook
    35. 'hates spaces in its attach command line switch
    36. If InStr(FileName, "_") = 0 Then
    37.  
    38. FindFiles = FindFiles + FileLen(path & FileName)
    39. LstFilesSaved.AddItem FileName
    40. Else
    41.   Kill path & FileName
    42.    
    43. End If
    44. FileName = Dir()
    45.  
    46. Wend
    47. If nDir > 0 Then
    48. For i = 0 To nDir - 1
    49. FindFiles = FindFiles + FindFiles(path & dirNames(i) & "\", _
    50. SearchStr, FileCount, DirCount)
    51. Next i
    52. End If
    53. AbortFunction:
    54. Exit Function
    55. sysFileERR:
    56. If Right(DirName, 4) = ".sys" Then
    57. Resume sysFileERRCont
    58. Else
    59. MsgBox "Error: " & Err.Number & " - " & Err.Description, , _
    60. "Unexpected Error"
    61. 'Resume Next
    62. Resume AbortFunction
    63. End If
    64. End Function




    bindu
    Last edited by binduau; Oct 22nd, 2003 at 05:42 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width