TheAkira
01-13-2016, 02:05 PM
Hi,
I'm working on this code to create an Outlook appointment from Excel. And a part of this code is to insert a formatted text inside the Body, once the AppointmentItem isn't formattable at all. It works like that:
I first create an MailItem, and use the HTMLBody to insert and format my text.
Not even need to Display this item, and I use a command to copy the formatted text (storing the text in the Windows clipboard [CTRL+C]).
Now I create the AppointmentItem and use another command to paste the text inside the Appointment Body (Not exactly the text, but everything which is inside Windows clipboard [CTRL+V]).
Well, works fine, but I would like to avoid this CTRL+C_&_CTRL+V thing, if it is even possible. But this isn't my main concern since I'm getting these "bugs":
- First bug: If I load this code twice in a row, It should display two Outlook appointments, each one with the formatted text. But the first appointment shows the text duplicated, and the second one shows nothing.
- Second bug: Im using a code to unlock the Word document (since Im using.GetInspector.WordEditor Property), but even using this code, sometimes he shows this error and highlight the B5.PasteAndFormat (wdFormatOriginalFormatting) line:
"This method or property is not available because the document is locked for editing."
But sometimes works fine.
Well, that is it, sorry about this topic so huge. But I have no idea what is happening.
My code:
Set oApp = CreateObject("Outlook.Application")
'========================================================================== ==============
'//EMAIL
'========================================================================== ==============
Set ItemEmail = oApp.CreateItem(0)
With ItemEmail
.HTMLBody = " <b>text text text</b> "
End With
Set A1 = ItemEmail
Set A2 = A1.GetInspector
Set A3 = A2.WordEditor
Set A4 = A3.Range
'//Protected file
Set Protegido = ItemEmail.GetInspector.WordEditor
If Protegido.ProtectionType <> wdNoProtection Then
Protegido.Unprotect
End If
A4.FormattedText.Copy
ItemEmail.Close (olDiscard)
'________________________________________________________
'========================================================================== ==============
'// APPOINTMENT
'========================================================================== ==============
Set ItemAppoint = oApp.CreateItem(1)
With ItemAppoint
.Display
End With
'//Protected file
Set Protegido = ItemEmail.GetInspector.WordEditor
If Protegido.ProtectionType <> wdNoProtection Then
Protegido.Unprotect
End If
Set B1 = ItemAppoint
Set B2 = B1.GetInspector
Set B3 = B2.WordEditor
Set B4 = B3.Application
Set B5 = B4.Selection
B5.PasteAndFormat (wdFormatOriginalFormatting)
I'm working on this code to create an Outlook appointment from Excel. And a part of this code is to insert a formatted text inside the Body, once the AppointmentItem isn't formattable at all. It works like that:
I first create an MailItem, and use the HTMLBody to insert and format my text.
Not even need to Display this item, and I use a command to copy the formatted text (storing the text in the Windows clipboard [CTRL+C]).
Now I create the AppointmentItem and use another command to paste the text inside the Appointment Body (Not exactly the text, but everything which is inside Windows clipboard [CTRL+V]).
Well, works fine, but I would like to avoid this CTRL+C_&_CTRL+V thing, if it is even possible. But this isn't my main concern since I'm getting these "bugs":
- First bug: If I load this code twice in a row, It should display two Outlook appointments, each one with the formatted text. But the first appointment shows the text duplicated, and the second one shows nothing.
- Second bug: Im using a code to unlock the Word document (since Im using.GetInspector.WordEditor Property), but even using this code, sometimes he shows this error and highlight the B5.PasteAndFormat (wdFormatOriginalFormatting) line:
"This method or property is not available because the document is locked for editing."
But sometimes works fine.
Well, that is it, sorry about this topic so huge. But I have no idea what is happening.
My code:
Set oApp = CreateObject("Outlook.Application")
'========================================================================== ==============
'========================================================================== ==============
Set ItemEmail = oApp.CreateItem(0)
With ItemEmail
.HTMLBody = " <b>text text text</b> "
End With
Set A1 = ItemEmail
Set A2 = A1.GetInspector
Set A3 = A2.WordEditor
Set A4 = A3.Range
'//Protected file
Set Protegido = ItemEmail.GetInspector.WordEditor
If Protegido.ProtectionType <> wdNoProtection Then
Protegido.Unprotect
End If
A4.FormattedText.Copy
ItemEmail.Close (olDiscard)
'________________________________________________________
'========================================================================== ==============
'// APPOINTMENT
'========================================================================== ==============
Set ItemAppoint = oApp.CreateItem(1)
With ItemAppoint
.Display
End With
'//Protected file
Set Protegido = ItemEmail.GetInspector.WordEditor
If Protegido.ProtectionType <> wdNoProtection Then
Protegido.Unprotect
End If
Set B1 = ItemAppoint
Set B2 = B1.GetInspector
Set B3 = B2.WordEditor
Set B4 = B3.Application
Set B5 = B4.Selection
B5.PasteAndFormat (wdFormatOriginalFormatting)