VBA를 사용하여지정된 디렉토리에서 .msg 파일을 열려고하려고하지만 런타임 오류가 계속 발생합니다.
내가 가진 코드 :
Sub bla()
Dim objOL As Object
Dim Msg As Object
Set objOL = CreateObject("Outlook.Application")
inPath = "C:\Users\SiliconPlus\Desktop\Si+ Contact Lists\Contact_Si+"
thisFile = Dir(inPath & "\*.msg")
Set Msg = objOL.CreateItemFromTemplate(thisFile)
' now use msg to get at the email parts
MsgBox Msg.Subject
Set objOL = Nothing
Set Msg = Nothing
End Sub
런타임 오류는 다음과 같습니다 :
Run-time error '-2147287038 (80030002)':
Cannot open file: AUTO Andy Low Yong Cheng is out of the office (returning 22 09 2014).msg.
The file may not exist, you may not have permission to open it, or it may be open in another program. Right-click the folder that contains the file, and then click properties to check your permissions for the folder.
- 답변 # 1
- 답변 # 2
오류가 발생하면 늦은 비딩을 시도(
Dim Msg As Object
)MsgBox
바로 아래 (주석을 제거해야 함) :Sub Kenneth_Li() Dim objOL As Outlook.Application Dim Msg As Outlook.MailItem Msgbox "If you get an error, try the Late Biding right under this (need to be uncommented)" 'Dim objOL As Object 'Dim Msg As Object Set objOL = CreateObject("Outlook.Application") inPath = "C:\Users\SiliconPlus\Desktop\Si+ Contact Lists\Contact_Si+" thisFile = LCase(Dir(inPath & "\*.msg")) Do While thisFile <> "" 'Set Msg = objOL.CreateItemFromTemplate(thisFile) 'Or 'Set Msg = objOL.OpenSharedItem(thisFile) 'Set Msg = GetNameSpace("MAPI").OpenSharedItem(thisFile) 'Eventually with Shell command (here for notepad) 'Shell "notepad " & thisFile Set Msg = objOL.Session.OpenSharedItem(thisFile) Msg.display MsgBox Msg.Subject thisFile = Dir Loop Set objOL = Nothing Set Msg = Nothing End Sub
또는 멋진 VB 솔루션을 찾을 수 있습니다 : http://www.mrexcel.com/forum/excel-questions/551148-open-msg-file-using-visual-basic-applications.html#post2721847
Shell
에 대한 자세한 내용은 여기를 참조하십시오. 방법 : http://p2p.wrox.com/access-vba/27776-how-open-msg-file-vbulletin.html#post138411 - 답변 # 3
다른 방법은 파일을 프로그래밍 방식으로 (VBA에서) 실행하는 것입니다
Shell
를 사용하십시오 명령). 항목이 열린 상태에서 활성 검사기 창을 얻을 수있는 Outlook에서 열립니다. - 답변 # 4
다음 코드를 확인하고 코드를 수정할 수 있습니다
Sub CreateFromTemplate() Dim MyItem As Outlook.MailItem Set MyItem = Application.CreateItemFromTemplate("C:\temp\*.msg") MyItem.Display End Sub
- 답변 # 5
이것을 시도하십시오
Sub GetMSG() ' True includes subfolders ' False to check only listed folder ListFilesInFolder "C:\Users\lengkgan\Desktop\Testing", True End Sub Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As Boolean) Dim FSO As Scripting.FileSystemObject Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder Dim FileItem As Scripting.File Dim strFile, strFileType, strAttach As String Dim openMsg As MailItem Dim objAttachments As Outlook.Attachments Dim i As Long Dim lngCount As Long Dim strFolderpath As String 'where to save attachments strFolderpath = "C:\Users\lengkgan\Desktop\Testing" Set FSO = New Scripting.FileSystemObject Set SourceFolder = FSO.GetFolder(SourceFolderName) For Each FileItem In SourceFolder.Files strFile = FileItem.Name ' This code looks at the last 4 characters in a filename ' If we wanted more than .msg, we'd use Case Select statement strFileType = LCase$(Right$(strFile, 4)) If strFileType = ".msg" Then Debug.Print FileItem.Path Set openMsg = Outlook.Application.CreateItemFromTemplate(FileItem.Path) openMsg.Display 'do whatever Set objAttachments = openMsg.Attachments lngCount = objAttachments.Count If lngCount > 0 Then For i = lngCount To 1 Step -1 ' Get the file name. strAttach = objAttachments.Item(i).Filename ' Combine with the path to the Temp folder. strAttach = strFolderpath & strAttach ' Save the attachment as a file. objAttachments.Item(i).SaveAsFile strAttach Next i End If openMsg.Close olDiscard Set objAttachments = Nothing Set openMsg = Nothing ' end do whatever End If Next FileItem If IncludeSubfolders Then For Each SubFolder In SourceFolder.SubFolders ListFilesInFolder SubFolder.Path, True Next SubFolder End If Set FileItem = Nothing Set SourceFolder = Nothing Set FSO = Nothing End Sub
수정 : 참조를 추가하는 방법
도구>참조를 클릭하십시오. 필요한 참조를 확인하십시오
관련 자료
- Excel VBA에서 루프를 사용하여 명명 된 범위를 만드는 방법은 무엇입니까?
- excel - 다른 시트의 참조 된 셀에 수식 사용
- vba를 사용하여 Excel에서 데이터 복사 및 붙여 넣기가 매우 느립니다
- python - openpyxl 모듈을 사용하여 Excel 시트에 값 복사
- Python을 사용하여 한 Excel 파일에서 다른 Excel 파일 시트로 열 복사
- vba - Excel Formua를 사용하여 모든 시트를 자동으로 합산하는 방법
- 테이블 배열에서 2 개의 열을 사용하는 Excel VLOOKUP
- express - 백엔드에서 excel4node를 사용하여 프론트 엔드에서 엑셀 파일 다운로드
- node.js - ExcelJS 및 노드 js를 사용하여 Excel 파일을 다운로드하는 중 브라우저에서 다운로드되지 않음
- for loop - 수식을 사용하여 Excel에서 값 검색
- powerbi - 파워 쿼리 편집기를 사용하여 Office Excel에서 데이터를 올바르게 표시하는 방법은 무엇입니까?
- Excel Range to Outlook Body with VBA - vba를 사용하는 outlook 본문에 대한 excel 범위 - 기본 서명을 추가하는 데 도움이 필요함
- Excel에서 VBA를 사용하여 'x'개의 행을 자동 채우기하는 방법
- python - Pandas 라이브러리를 사용하여 Excel 파일에서 줄을 삭제하는 방법
- Excel VBA - excel vba - 3 개의 행 요소와 1 개의 열 요소를 사용하여 피벗 테이블에서 데이터 가져 오기
- Excel을 사용하여 수업 명단/출석 목록 정렬
- python - xlsxwriter를 사용하여 데이터 프레임을 Excel 파일로 내보내기
- excel : 직접 경로없이 서명과 이미지가있는 이메일을 보내려면 어떻게해야합니까?
- excel : VBA에서 사용자 지정 대량 전자 메일을 만들려면 어떻게합니까?
- excel : 가변 길이 목록의 셀 값으로 이메일 텍스트 채우기
- excel : 이메일 데이터를 통합 문서로 내보낼 때 데이터가 이미 워크 시트에 있는지 확인하는 방법은 무엇입니까?
- 기준에 따라 이메일을 전달하는 Excel VBA
- Excel 매크로를 사용하여 Outlook 의제를 보낼 수 있습니까?
- Excel을 사용하여 Outlook에서 이메일 전달을 자동화 할 수 있습니까?
- excel : 로컬 폴더에 메시지를 저장하는 방법은 무엇입니까?
- excel : MinimizeOutlookWindow가 작동하지 않음
- VBA Excel 365-Outlook 검색 폴더의 메일 수 계산
케네스 리 파일을 열 때 전체 경로가 없었습니다. 이것을 시도하십시오 :