0

I'm trying to edit an OFT with vba code

Private Sub CommandButton1_Click()

template = "T:\Coordination des interventions\Coordination des changements\Communications\Interruption de service planifiée - Environnements applicatifs Oracle - Copie.oft"

strNew = InputBox("Jour de la semaine")

strFind = "%>JourSemaine<%"


Dim oApp As Object, oMail As Object

Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItemFromTemplate(template)

With oMail
    'strFind = "Code:"
    'strNew = "Code:" & Cells(4, 3) ' for example
    .HTMLBody = Replace(oMail.HTMLBody, strFind, strNew)

    .Display

End With

End Sub

This is where I got an error 287 (my systeme is in french)

    .HTMLBody = Replace(oMail.HTMLBody, strFind, strNew)

Anybody have clue?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Sylvain
  • 1
  • 2

2 Answers2

1

Make sure that you set up a well-formed HTML markup. For example:

With oMail 
  'Set body format to HTML 
  .BodyFormat = olFormatHTML 
  .HTMLBody = "<HTML><BODY>Enter the message text here. </BODY></HTML>" 
  .Display 
End With 

Calling the Replace method you may replace some HTML tags as well.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
1

Obvious thing to me, not that I am outlook vba expert, but if is purely a html issue as the person above me has said but failed to spell out - your strFind includes the html tags '>' and '<' so why haven't you added them in your strNew. If I am to assume rather that was just typo on your behalf and your actual code is replace "Code:" with "Code: " + Cells(4, 3) then I would be asking myself what is in Cells(4, 3) is it html encoded i.e. the common mistakes people make are does the text contain tags (e.g. '>' or '<') or ampersand ('&') then you need to change it with a replace function e.g. Replace(Cells(4, 3), "&", "&amp;") or find a predefined function that encodes it for you. In your case I am guessing being French perhaps you text contains uni-code characters like letters with accents and graves etc. that will also need to be encoded.

Glen
  • 802
  • 1
  • 11
  • 27