Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

issue where when the font is different at the point of insertion, it types out in that font and size

Posted on 2009-05-03
5
Medium Priority
?
293 Views
Last Modified: 2012-05-06
I had previously tested it just in a new task and it worked fine.

However, when I have gone to some existing tasks, where inadvertently ( not deliberately! ) the standard font is different, then when I run the macro, to insert the day and time, it inserts the day and time, but in the font that is at that point in the task and then changes it to Arial, 12 etc . . .

Is it possible to alter the code, to allow for this?
0
Comment
Question by:troy_g
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24293163
The bit below does not change the general body text ... is that what you want?

Chris
Sub InsertAndFormatText()
    Const wdColorBlue = 16711680
    Dim olkTask As Outlook.TaskItem, _
        objDoc As Object, _
        objSel As Object, _
        strTime As String, _
        intStart As Integer, _
        intLen As Integer
    Set olkTask = Outlook.Application.ActiveInspector.CurrentItem
    Set objDoc = olkTask.GetInspector.WordEditor
    strTime = Format(Now, "ddd dd/m/yy h:mm AM/PM - ")
    intLen = Len(strTime)
    Set objSel = objDoc.Windows(1).Selection
    intStart = objSel.Start
    objSel.InsertAfter strTime
    objDoc.Windows(1).Document.Range(intStart, intStart + intLen).Select
    Set objSel = objDoc.Windows(1).Selection
    With objSel
        .Font.Bold = True
        .Font.Color = wdColorBlue
    End With
    objDoc.Windows(1).Document.Range(intStart + intLen - 1, intStart + intLen + 1).Select
'    Set objSel = objDoc.Windows(1).Selection
'    With objSel
'        .Font.Name = "Arial"
'        .Font.Size = 12
'        .Font.Bold = False
'        .Font.Color = wdColorAutomatic
'    End With
    Set olkTask = Nothing
    Set objDoc = Nothing
    Set objSel = Nothing
End Sub 
Open in New Window Select All 

Open in new window

0
 

Author Comment

by:troy_g
ID: 24294442
Hi Chris - thanks so much for your response, this doesn't do exactly as i need.

If you go into an empty task in Outlook and change the font and size for the line you are on as an example and then run this Macro, it will type out the Date & Time in that font and size, whereas i am just needing a standard format like Arial, Point Size 12, Bold  & Blue text.  Then, after the '-' ( ie. at the end of the date / time stamp ) i just need need it to take off the Bold and Blue part and just have typing show up as Arial & Size 12 Font.

Hope this makes sense ? Thanks so much for assisting and please let me know if you need any further info . . .
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24294580
If I understand correctly then More like this?

Chris
Sub InsertAndFormatText()
    Const wdColorBlue = 16711680
    Dim olkTask As Outlook.TaskItem, _
        objDoc As Object, _
        objSel As Object, _
        strTime As String, _
        intStart As Integer, _
        intLen As Integer
    Set olkTask = Outlook.Application.ActiveInspector.CurrentItem
    Set objDoc = olkTask.GetInspector.WordEditor
    strTime = Format(Now, "ddd dd/m/yy h:mm AM/PM - ")
    intLen = Len(strTime)
    Set objSel = objDoc.Windows(1).Selection
    intStart = objSel.Start
    objSel.InsertAfter strTime
    Set objSel = objDoc.Windows(1).document.range
    With objSel
        .Font.Name = "Arial"
        .Font.Size = 12
        .Font.Bold = False
        .Font.Color = wdColorAutomatic
    End With
    objDoc.Windows(1).Document.Range(intStart, intStart + intLen).Select
    Set objSel = objDoc.Windows(1).Selection
    With objSel
        .Font.Bold = True
        .Font.Color = wdColorBlue
    End With
    objDoc.Windows(1).Document.Range(intStart + intLen - 1, intStart + intLen + 1).Select
    Set olkTask = Nothing
    Set objDoc = Nothing
    Set objSel = Nothing
End Sub 

Open in new window

0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 24294765
Looking at the previous one you want a hard return after the time post, so the following makes that correction

Chris
Sub InsertAndFormatText()
    Const wdColorBlue = 16711680
    Dim olkTask As Outlook.TaskItem, _
        objDoc As Object, _
        objSel As Object, _
        strTime As String, _
        intStart As Integer, _
        intLen As Integer
    Set olkTask = Outlook.Application.ActiveInspector.CurrentItem
    Set objDoc = olkTask.GetInspector.WordEditor
    strTime = Format(Now, "ddd dd/m/yy h:mm AM/PM - ")
    intLen = Len(strTime)
    Set objSel = objDoc.Windows(1).Selection
    intStart = objSel.Start
    objSel.InsertAfter strTime & vbCrLf
    Set objSel = objDoc.Windows(1).Document.Range
    With objSel
        .Font.Name = "Arial"
        .Font.Size = 12
        .Font.Bold = False
        .Font.Color = wdColorAutomatic
    End With
    objDoc.Windows(1).Document.Range(intStart, intStart + intLen).Select
    Set objSel = objDoc.Windows(1).Selection
    With objSel
        .Font.Bold = True
        .Font.Color = wdColorBlue
    End With
    objDoc.Windows(1).Document.Range(intStart + intLen - 1, intStart + intLen + 1).Select
    Set olkTask = Nothing
    Set objDoc = Nothing
    Set objSel = Nothing
End Sub

Open in new window

0
 

Author Closing Comment

by:troy_g
ID: 31577456
thanks heaps Chris, that is fantastic, and works, appreciate it !
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question