0

我有以下代码,用于转发电子邮件,并包含我自己的消息。

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 坐标),但不是出于某种原因,我不明白为什么。

任何机构有什么建议吗?

4

1 回答 1

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

如果您发送更多信息,您在发送邮件时遇到什么问题,我也会尽力帮助您。

最大限度

于 2013-11-15T22:34:59.227 回答