我有以下代碼是爲了轉發電子郵件,幷包含我自己的消息。從文本文件中讀取值,轉發電子郵件
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座標),但它不是由於某種原因,我不明白爲什麼。
確實有任何建議嗎?
你應該爲此創造兩個不同的問題。在回答你的第一個問題時,你實際上需要創建一個包含你想要的所有數據的新文本文件。編輯文本文件的唯一方法就是使用ADO,我甚至不確定你可以用它做。我知道ADO只能用於訪問結構化文本文件,如XML或CSV。 – HK1