【发布时间】:2019-03-21 11:49:00
【问题描述】:
我在 Windows 上通过命令提示符运行,并在第 24 行和第 34 个字符处收到警报
代码示例如下:
Sub CatchMe()
Dim outobj, mailobj
Dim strFileText
Dim objFileToRead
Set outobj = CreateObject("Outlook.Application")
Set mailobj = outobj.CreateItem(0)
strFileText = GetText("C:\Users\Yatheesh.Sathyanaray.STDC\Documents1.txt")
With mailobj
.To = "yatheesh.satyanarayana@stratogent.com"
.Subject = "Testmail"
.Body = strFileText
.Display
End With
'Clear the memory
Set outobj = Nothing
Set mailobj = Nothing
End Sub
Function GetText(sFile As String) As String
Dim nSourceFile As Integer, sText As String
nSourceFile = FreeFile
'Write the entire file to sText
Open sFile For Input As #nSourceFile
sText = Input$(LOF(1), 1)
Close
GetText = sText
End Function
【问题讨论】:
-
VBScript不允许您将变量定义为String之类的类型,因此您需要删除所有as Integer或as String语句... -
整个函数
GetText()将失败,在 VBScript 中,如果您想读取文件,请使用Scripting.FileSystemObject,Stack Overflow 上有很多示例。
标签: vbscript outlook office365