2011-05-03 4 views
1

우리는 아웃룩 2010을 사용하는 우리의 VB6 코드를 업그레이드 할, 그러나 우리는 다음과 같은 오류가 있어요 :업그레이드 VB6 코드 2010

Public Sub SendEmail() 

    Set emailOutlookApp = CreateObject("Outlook.Application.12") 

    Set emailNameSpace = emailOutlookApp.GetNamespace("MAPI") 
    Set emailFolder = emailNameSpace.GetDefaultFolder(olFolderInbox) 

    Set emailItem = emailOutlookApp.CreateItem(olMailItem) 
    Set EmailRecipient = emailItem.Recipients 
    EmailRecipient.Add (EmailAddress) 
    EmailRecipient.Add (EmailAddress2) 

    emailItem.Importance = olImportanceHigh 
    emailItem.Subject = "My Subject" 
    emailItem.Body = "The Body" 

'-----Send the Email-----' 
    emailItem.Save 
    emailItem.Send 

'-----Clear out the memory space held by variables-----' 
    Set emailNameSpace = Nothing 
    Set emailFolder = Nothing 
    Set emailItem = Nothing 
    Set emailOutlookApp = Nothing 
Exit Sub 
: 이것은 우리의 현재 코드가 Active x cannot create object

입니다

"Outlook.Application.12"가 올바른지 확실하지 않습니다. 그러나 이것에 대한 확실한 답을 찾을 수는 없습니다.

+0

빠른 검색 후 2010 년이 "Outlook.Application.14"가 표시됩니다. – pickypg

답변

0

시도 "Outlook.Application.14". 이게 관련이 있는지 확실하지 않은 경우 : 2007 to 2010 upgrade issue

정확한 문제는 아니지만 정확한 경로로 안내 할 수 있습니다.

+0

이 작동하지 않습니다. ( – elcool

2

여기에 내가 2010 년에 전환 코드는 다음과 같습니다

Private Sub EmailBlahbutton_Click() 

Dim mOutlookApp As Object 
Dim OutMail As Object 
Dim Intro As String 

On Error GoTo ErrorHandler 

Set mOutlookApp = GetObject("", "Outlook.application") 
Set OutMail = mOutlookApp.CreateItem(0) 

With Application 
    .EnableEvents = False 
    .ScreenUpdating = False 
End With 

'These are the ranges being emailed. 
ActiveSheet.Range(blahblahblah).Select 

'Intro is the first line of the email 
Intro = "BLAHBLAHBLHA" 

'Set the To and Subject lines. Send the message. 
With OutMail 
    .To = "[email protected]" 
    .Subject = "More BLAH here" 
    .HTMLBody = Intro & RangetoHTML(Selection) 
    .Send 
End With 

With Application 
    .EnableEvents = True 
    .ScreenUpdating = True 
End With 

ActiveSheet.Range("A1").Select 
ActiveWindow.ScrollColumn = ActiveCell.Column 
ActiveWindow.ScrollRow = ActiveCell.Row 

Set OutMail = Nothing 
Set mOutlookApp = Nothing 

Exit Sub 

ErrorHandler: 
    Set mOutlookApp = CreateObject("Outlook.application") 
    Resume Next 

End Sub 

Function RangetoHTML(rng As Range) 
' Changed by Ron de Bruin 28-Oct-2006 
' Working in Office 2000-2010 
Dim fso As Object 
Dim ts As Object 
Dim TempFile As String 
Dim TempWB As Workbook 

TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm" 

'Copy the range and create a new workbook to past the data in 
rng.Copy 
Set TempWB = Workbooks.Add(1) 
With TempWB.Sheets(1) 
    .Cells(1).PasteSpecial Paste:=8 
    .Cells(1).PasteSpecial xlPasteValues, , False, False 
    .Cells(1).PasteSpecial xlPasteFormats, , False, False 
    .Cells(1).Select 
    Application.CutCopyMode = False 
    On Error Resume Next 
    .DrawingObjects.Visible = True 
    .DrawingObjects.Delete 
    On Error GoTo 0 
End With 

'Publish the sheet to a htm file 
With TempWB.PublishObjects.Add(_ 
    SourceType:=xlSourceRange, _ 
    Filename:=TempFile, _ 
    Sheet:=TempWB.Sheets(1).Name, _ 
    Source:=TempWB.Sheets(1).UsedRange.address, _ 
    HtmlType:=xlHtmlStatic) 
    .Publish (True) 
End With 

'Read all data from the htm file into RangetoHTML 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2) 
RangetoHTML = ts.ReadAll 
ts.Close 
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _ 
         "align=left x:publishsource=") 

'Close TempWB 
TempWB.Close savechanges:=False 

'Delete the htm file we used in this function 
Kill TempFile 

Set ts = Nothing 
Set fso = Nothing 
Set TempWB = Nothing 

End Function 
2

왜 당신은 명시 적으로 버전을 지정합니까? 단순히 으로 설정하십시오. 이메일을 설정하십시오 .OutlookApp = CreateObject ("Outlook.Application")

+0

은 명시 적으로 수행 할 수 없다는 것을 모릅니다. : P 사용해 보겠습니다. – elcool

3

Outlook 2010의 경우 이는 분명히 핵심 항목 Outlook.Application.14입니다. 그러나 나는 사무실 2007에 대해 무엇을 해야할지 모르겠다. 나는 그것이 Outlook.Application.12이라고 생각하고 하위 버전은 단순히 "Outlook.Application"이라고 생각한다.

관련 문제