如何用VB将将一段代码写入txt
用VB创建一个TXT文本,然后写入以下代码?
Function MyCalc()
NameSpace = "http://schemas.microsoft.com/cdo/configuration/"
Set Email = CreateObject("CDO.Message")
Email.From =From
Email.To =toEmail
Email.Subject =Subject
Email.Textbody =Textbody
Email.AddAttachment AddAttachment
With Email.Configuration.Fields
.Item(NameSpace&"sendusing") = 2
.Item(NameSpace&"smtpserver") = smtpserver
.Item(NameSpace&"smtpserverport") = 25
.Item(NameSpace&"smtpauthenticate") = 1
.Item(NameSpace&"sendusername") =sendusername
.Item(NameSpace&"sendpassword") =sendpassword
.Update
End With
Email.Send
end function
[解决办法]
Private Sub Command1_Click()Dim s As Strings = "Function MyCalc() " & vbCrLf _& "NameSpace =" & """" & "http://schemas.microsoft.com/cdo/configuration/" & """" & vbCrLf _& "Set Email = CreateObject(" & """" & "CDO.Message" & """" & ")" & vbCrLf _& "Email.From = From " & vbCrLf _& "Email.To = toEmail" & vbCrLf _& "Email.Subject = Subject" & vbCrLf _& "Email.Textbody = Textbody " & vbCrLf _& "Email.AddAttachment AddAttachment " & vbCrLf _& "With Email.Configuration.Fields" & vbCrLf _& "With Email.Configuration.Fields" & vbCrLf _& "With Email.Configuration.Fields" & vbCrLf _& "With Email.Configuration.Fields" & vbCrLf _& "With Email.Configuration.Fields" & vbCrLf _& "With Email.Configuration.Fields" & vbCrLf _& "With Email.Configuration.Fields" & vbCrLf _& ".Item(NameSpace&" & """" & "sendusing" & """" & ") = 2" & vbCrLf _& ".Item(NameSpace&" & """" & "smtpserver" & """" & ") = smtpserver" & vbCrLf _& ".Item(NameSpace&" & """" & "smtpserverport" & """" & ") = 25" & vbCrLf _& ".Item(NameSpace&" & """" & "smtpauthenticate" & """" & ") = 1" & vbCrLf _& ".Item(NameSpace&" & """" & "sendusername" & """" & ") =sendusername" & vbCrLf _& ".Item(NameSpace&" & """" & "sendpassword" & """" & ") =sendpassword" & vbCrLf _& ".Update" & vbCrLf _& "End With" & vbCrLf _& "Email.Send" & vbCrLf _& "end function" & vbCrLfOpen "C:\001.txt" For Output As #1Print #1, s Close #1End Sub