내가 원했던 부분에 대한 온라인 코드를 발견했습니다. 평상시처럼 Visual Studio에서 실행했는데 문제가 없습니다.VB (MSVisualStudio 2005) 및 VBA (Excel)과 다른 점 찾기
이 문제는 Excel로 이식하려고하면 작동을 멈추는 문제가 발생합니다. 제가 아는 바에 따르면 VBA는 VB의 다운 된 버전입니다. (이 기사를 읽을 때 기준 : Difference between Visual Basic 6.0 and VBA)
따라서 두 프로그래밍 환경간에 갈 때 무엇이 손실되는지 어떻게 알 수 있습니까?
좀 더 자세히 알려면 : Visual Studio에서 버튼을 누르면 이메일이 전송되는 프로그램을 작성했습니다. 그런 다음 Excel로 매크로로 포트하려고했지만 작동하지 않았습니다.
편집 :
: Adeed 추가 문제 정보 여기내가 비주얼 스튜디오 공공 Form1 클래스
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CDO_Mail_Small_Text()
End Sub
Sub CDO_Mail_Small_Text()
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
Dim Flds As Object
iMsg = CreateObject("CDO.Message")
iConf = CreateObject("CDO.Configuration")
iConf.Load(-1) ' CDO Source Defaults
Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
= "morgan"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update()
End With
strbody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4"
With iMsg
.Configuration = iConf
.To = "[email protected]"
.CC = ""
.BCC = ""
.From = """Ron"" <[email protected]>"
.Subject = "Important message"
.TextBody = strbody
.Send()
End With
End Sub
최종 클래스
여기내가 Excel에서 실행 한 무슨을에있는 것입니다
Sub Button1_Click()
CDO_Mail_Small_Text
End Sub
Sub CDO_Mail_Small_Text()
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
Dim Flds As Object
iMsg = CreateObject("CDO.Message")
iConf = CreateObject("CDO.Configuration")
iConf.Load (-1)
Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
= "morgan"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
strbody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4"
With iMsg
.Configuration = iConf
.To = "[email protected]"
.CC = ""
.BCC = ""
.From = """Ron"" <[email protected]>"
.Subject = "Important message"
.TextBody = strbody
.Send
End With
End Sub
작동하지 않는 부분은 다음과 같습니다.,"런타임 오류 '91': 개체 변수 또는 With 블록 변수가 설정되지" "iMsg = CreateObject를 ("CDO.Message ")"
나는 그것이 다음 줄에 저를 소요 디버깅
건배, 예레미야 Tantongco
코드를 제공 객체 또는 적어도 작업 할 때 VB6/VBA에서
http://www.rondebruin.nl/sendmail.htm
–