Folgendes Problem:
Ich habe ein Mailtemplate was ich mit Comate aufrufe und soweit auch ausfülle.
Ich möchte im MailBody Text suchen und dann ersetzen z.B.: 2017 in 1966 abändern...
Alle Versuche funktionieren nicht...
Wenn mal jemand ne ordentliche Anleitung für Comate schreiben könnte )-:
Hier mal der Code der das Template aufruft... Ich kann auch den Mailbody auslesen aber man bekommt den nur als Plaintext wieder rein so das alle Formatierungen verloren gehen...
Es Soll ja gehen mit dem hier z.B.
Das ist von hier:http://stackoverflow.com/questions/3023 ... litem-body
Code: Alles auswählen
 public static void Replace(Microsoft.Office.Interop.Word.Range rng, string OldValue, object NewValue)
 {
        object missing = System.Reflection.Missing.Value;
        try
        {
            Find findObject = rng.Find;
            findObject.ClearFormatting();
            findObject.Text = OldValue;
            findObject.Replacement.ClearFormatting();
            findObject.Format = true;
            object replaceAll = WdReplace.wdReplaceAll;
            findObject.Execute(ref missing, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing, NewValue,
               ref replaceAll, ref missing, ref missing, ref missing, ref missing);
        }
        catch (System.Exception e)
        {
            throw e;
        }
}Aber wie baue ich das hier ein ?
Code: Alles auswählen
IncludePath "C:\Users\sdleidel\Desktop\PureBasic\COMatePLUS_PB5\"
XIncludeFile "C:\Users\sdleidel\Desktop\PureBasic\COMatePLUS_PB5\COMatePLUS.pbi"
Define COMateObject
Define OutlookObject.COMateObject 
Define olMsg.COMateObject
Define olMsgr.COMateObject
search$ = "2017"
replace$ = "1966"
#wdReplaceAll  = 2
Procedure ShowErrorIfAny() 
  If COMate_GetLastErrorCode() : Debug COMate_GetLastErrorDescription() : EndIf 
EndProcedure 
sub.s="*** Attachment ***"
standard.s= "Hello"
tomail.s="xx@xxxx.de"
add.s=#PB_Compiler_Home+"transactions.txt"
OutlookObject = COMate_CreateObject("Outlook.Application")
If OutlookObject 
  ; olMsg = OutlookObject\GetObjectProperty("CreateItem(0)")
  olMsg = OutlookObject\GetObjectProperty("CreateItemFromTemplate('C:\Users\appnd\Desktop\PureBasic\sources\Vorlage1.oft')")
     ;olMsg = OutlookObject\GetObjectProperty("Open('C:\Users\sdleidel\Desktop\PureBasic\Comate_Source\ComateTest.docx')")
If olMsg
  test$= olMsg\GetStringProperty("HTMLBody")
  test2$=olMsg\GetStringProperty("Body")
  ;Debug test$
  such$="2017"
  Debug FindString(test2$,such$)
 ; olMsg\SetProperty("Body='"+test$+"'") 
  
  ShowErrorIfAny()
  ;Debug test$
  Debug test2$
  olMsg\Invoke("Display") 
  ShowErrorIfAny()
 ;Debug olMsgr
 
 
If FileSize(add)<>-1
 olMsg\SetProperty("Attachments\Add('"+add+"')")
EndIf
 
olMsg\Invoke("Display")
;olMsg\Invoke("Send")
olMsg\Release()
 Else
 MessageRequester("Sorry", COMate_GetLastErrorDescription()) 
EndIf
OutlookObject\Release()
Else
 MessageRequester("Sorry - CreateObject", COMate_GetLastErrorDescription())
EndIf
ShowErrorIfAny()