2012-04-20 4 views
1

전자 메일 주소에 따라 전자 메일 첨부 파일을 폴더에 저장하는 VBA 매크로를 만들려고합니다. 예를 들어 [email protected]에서 첨부 파일을 받고 이메일로 첨부 파일 인 \ server \ home \ joey 에 저장하려고하거나 [email protected]에서받은 경우 첨부 파일을 저장해야합니다. \ server \ home \ steve.첨부 파일을 네트워크 위치에 저장

마지막으로 저장 한 파일의 이름이 포함 된 답장 전자 메일을 보내려고합니다. 거의 원하는 코드를 찾았지만 수정하기가 힘듭니다. 이것은 모두 Outlook 2010에서 수행되고 있습니다. 이것은 내가 지금까지 가지고있는 것입니다. 어떤 도움이라도 대단히 감사하겠습니다.

Const mypath = "\\server\Home\joe\" 
Sub save_to_v() 

    Dim objItem As Outlook.MailItem 
    Dim strPrompt As String, strname As String 
    Dim sreplace As String, mychar As Variant, strdate As String 
    Set objItem = Outlook.ActiveExplorer.Selection.item(1) 
    If objItem.Class = olMail Then 

     If objItem.Subject <> vbNullString Then 
      strname = objItem.Subject 
     Else 
      strname = "No_Subject" 
     End If 
     strdate = objItem.ReceivedTime 

     sreplace = "_" 

     For Each mychar In Array("/", "\", ":", "?", Chr(34), "<", ">", "|") 

      strname = Replace(strname, mychar, sreplace) 
      strdate = Replace(strdate, mychar, sreplace) 
     Next mychar 

     strPrompt = "Are you sure you want to save the item?" 
     If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then 
      objItem.SaveAs mypath & strname & "--" & strdate & ".msg", olMSG 
     Else 
      MsgBox "You chose not to save." 
     End If 
    End If 
End Sub 

답변

1

이것이 무엇입니까? 그것은 작동하지 않습니다

Option Explicit 

Const mypath = "\\server\Home\" 

Sub save_to_v() 

    Dim objItem As Outlook.MailItem 
    Dim strPrompt As String, strname As String, strSubj As String, strdate As String 
    Dim SaveAsName As String, sreplace As String 
    Dim mychar As Variant 

    Set objItem = Outlook.ActiveExplorer.Selection.Item(1) 

    If objItem.Class = olMail Then 

     If objItem.Subject <> vbNullString Then 
      strSubj = objItem.Subject 
     Else 
      strSubj = "No_Subject" 
     End If 

     strdate = objItem.ReceivedTime 

     sreplace = "_" 

     For Each mychar In Array("/", "\", ":", "?", Chr(34), "<", ">", "|") 
      strSubj = Replace(strSubj, mychar, sreplace) 
      strdate = Replace(strdate, mychar, sreplace) 
     Next mychar 

     strname = objItem.SenderEmailAddress 

     strPrompt = "Are you sure you want to save the item?" 

     If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then 
      Select Case strname 
      Case "[email protected]" 
       SaveAsName = mypath & "joey\" & strSubj & "--" & strdate & ".msg" 
      Case "[email protected]" 
       SaveAsName = mypath & "steve\" & strSubj & "--" & strdate & ".msg" 
      End Select 

      objItem.SaveAs SaveAsName, olMSG 
     Else 
      MsgBox "You chose not to save." 
     End If 
    End If 
End Sub 
+0

귀하의 도움에 감사드립니다. –

0

(안된). Outlook 2010에서는 msg 파일을 네트워크 드라이브에 저장하지 않으므로 로컬 드라이브 만 작동합니다 !! M $의 문서에 설명되어 있고 나와 테스트를 거쳤습니다. 고정 경로 및 파일 이름으로 간단한 테스트. 로컬 c : \는 작동합니다. UNC 또는 L의 네트워크 드라이브가 작동하지 않습니다. !!!!

관련 문제