我有以下代码,用于转发电子邮件,并包含我自己的消息。
Private Sub Items_ItemAdd(ByVal item As Object)
Dim filenum As Integer
Dim current_number As String
filenum = FreeFile()
Open "G:\Infrastructure Services\Engineering Services\Hazard Report Number.txt" For Input As #filenum
While Not EOF(filenum)
Line Input #filenum, current_number
Wend
If item.Class = olMail Then
If Left$(item.Subject, 29) = "Hazard Identification Report" Then
Dim Msg As Outlook.MailItem
Dim NewForward As Outlook.MailItem
Dim myFolder As Outlook.MAPIFolder
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Set Msg = item
Set NewForward = Msg.Forward
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
strSender = ""
strsenderName = Msg.SenderEmailAddress
If strsenderName = "EX" Then
Set objSender = itm.Sender
If Not (objSender Is Nothing) Then
Set objExchUser = Sender.GetExchangeUser()
If Not (objExchUser Is Nothing) Then
strSender = objExchUser.PrimarySmtpAddress
End If
End If
Else
strSender = strsenderName
End If
With NewForward
.Subject = "Hazard report reciept number:"
.To = strSender
.HTMLBody = "TYhank you for your email"
.Send
End With
End If
End If
ExitProc:
Set NewForward = Nothing
Set Msg = Nothing
Set olApp = Nothing
Set olNS = Nothing
End Sub
我从我的文本文件中读取了值,没问题。我的问题是如何从文本文件中删除值,并将值+1打印回文本文件?
另外,这是为了将消息转发给发件人,包括他们的原始附件和消息(照片和一些GPS坐标),但它不是出于某种原因而且我看不出原因。
是否有任何机构有任何建议?
答案 0 :(得分:0)
我不太明白你的第二个问题是什么(“但不是出于某种原因,我不明白为什么”不是完美的错误描述)。
但是要用新值替换txt文件,请使用:
Call textfile_replace(Value + 1)
这是您需要的代码:
Sub textfile_replace(mytext As String)
On Error GoTo Fehler
Dim Datei As String
Dim Fnr As Long
Datei = "c:\mytest.txt"
Fnr = FreeFile
Open Datei For Output As Fnr
Print #Fnr, mytext
Close Fnr
Exit Sub
Fehler:
MsgBox "error" & Err.Number & " " & Err.Description
End Sub
如果您发送更多信息,您发送邮件时会遇到什么问题,我也会尽力为您提供帮助。
最高