2017-04-20 2 views
1

아래 코드는 내받은 편지함에서 내 Subfolder을 찾은 다음 활성 창에서 전자 메일을 엽니 다.pdf의 필드를 사용하여 PDF 첨부 파일 저장

나는 "Open"이 이메일에 첨부 된 pdf 형태 그래서 나는 pdf 양식에서 텍스트 필드 중 하나를 사용하여 첨부 파일을 저장할 수 싶습니다.

찾을 수있는 유일한 코드는 첨부 파일을 임시 폴더에 저장하지만 pdf 양식의 콘텐츠를 가져 오지 못합니다.

Sub OpenMailAttachment() 

    Dim ns As NameSpace 
    Dim Inbox As MAPIFolder 
    Dim openMsg As Outlook.MailItem  
    Dim mySubFolder As MAPIFolder 
    Dim myAttachment As Outlook.Attachment 
    Dim FileName As String  
    Dim myInspector As Outlook.Inspector 

    Set ns = GetNamespace("MAPI") 
    Set Inbox = ns.GetDefaultFolder(olFolderInbox) 
    Set mySubFolder = Inbox.Folders("PdfTest") 

    mySubFolder.Display 

    Set openMsg = mySubFolder.Items(1) 

    openMsg.Display 

    mySubFolder.Application.ActiveExplorer.Close 

    openMsg.Application.ActiveWindow 

    For Each myAttachment in Item.Attachment 
     FileName = "C:\temp\" & myAttachment.FileName 

     myAttachment.SaveAsFile FileName 

     myAttachment = openMsg.Attachments.Item.DisplayName 
     '(I get Compile error: *.Item* argument not optional) 

     myAttachments.Application.ActiveInspector.Display 

End Sub 
+0

https://meta.stackexchange.com/a/5235/289619 – 0m3r

답변

1

이 Off로 명시 적 옵션을 설정

은 일반적으로 끈적 거리는 아니다

Option Explicit 
' use Declare PtrSafe Function with 64-bit Outlook 
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (_ 
    ByVal hwnd As Long, _ 
    ByVal lpOperation As String, _ 
    ByVal lpFile As String, _ 
    ByVal lpParameters As String, _ 
    ByVal lpDirectory As String, _ 
    ByVal nShowCmd As Long _ 
) As Long 

Sub OpenMailAttachment() 
    Dim ns As NameSpace 
    Dim Inbox As MAPIFolder 
    Dim openMsg As Outlook.MailItem 
    Dim mySubFolder As MAPIFolder 
    Dim Attachment As Outlook.Attachment 
    Dim myAttachments As Outlook.Attachments 
    Dim FileName As String 
    Dim myInspector As Outlook.Inspector 
    Dim Item As Object 
    Dim sFileType As String 

    Set ns = GetNamespace("MAPI") 
    Set Inbox = ns.GetDefaultFolder(olFolderInbox) 
    Set mySubFolder = Inbox.Folders("PdfTest") 

    mySubFolder.Display 

    Set openMsg = mySubFolder.Items(1) 

    openMsg.Display 
    mySubFolder.Application.ActiveExplorer.Close 
    openMsg.Application.ActiveWindow 

    Set myAttachments = openMsg.Attachments 

    If myAttachments.Count Then 
     For Each Attachment In myAttachments 
      'Last 4 Characters in a Filename 
      sFileType = LCase$(Right$(Attachment.FileName, 4)) 

      Select Case sFileType 
       ' Add additional file types below 
       Case ".pdf" ', ".doc", "docx", ".xls" 

       FileName = "C:\temp\" & Attachment.FileName 
       Attachment.SaveAsFile FileName 
       ShellExecute 0, "open", FileName, vbNullString, vbNullString, 0 
      End Select 
     Next 
    End If 


End Sub 

Option Explicit Statement (Visual Basic) ... 그것을해야 연습. 하나 이상의 위치에서 변수 이름의 철자를 잘못 입력하면 프로그램을 실행할 때 예기치 않은 결과가 발생할 수 있습니다.

+0

(가) PDF를 열 않습니다하지만 내 전망을 종료 유지합니다. 오류 메시지 : MS Outlook이 작동을 멈췄습니다. 문제로 인해 프로그램이 올바르게 작동하지 않습니다. – CPmngr

+0

@CPmngr 실행중인 Outlook 버전은 무엇입니까? – 0m3r