【问题标题】:How can I change the default font of Outlook 2016?如何更改 Outlook 2016 的默认字体?
【发布时间】:2023-02-03 21:16:32
【问题描述】:

我想在 Microsoft Office(不是 365)中将默认的 Arial 字体类型更改为 Montserrat。

我正在关注 herehere 所呈现的内容。我还被告知我应该尝试在 PowerShell 中运行它,但我不知道如何运行。

以下是我到目前为止创建的内容:

Sub ChangeFont()
    Dim objOLApp As Outlook.Application
    Dim NewTask As Outlook.TaskItem 
    Set objOLApp = New Outlook.Application
    Set NewTask = objOLApp.CreateItem(0)

    with Newtask
        .DefaultFont = "Montserrat"
    End With

    On Error Resume Next
END Sub

WScript.Echo "Done!"

pause

exit

将其另存为 .vbs 文件并双击该文件时,出现以下错误:

【问题讨论】:

  • 据我所知,vbScript 不允许类型声明,例如As Outlook.Application。仅声明变量名称并将Set objOLApp = New Outlook.Application 更改为Set objOLApp = CreateObject("Outlook.Application")
  • 如果您没有安装 outlook,VBScript 环境如何创建 Outlook 对象?
  • @FunThomas 我目前没有在我的个人设备上安装它,但稍后我可以在另一台装有 Outlook 的设备上对其进行测试。抱歉造成混淆,应该提到它。我会编辑我的帖子。
  • 提供的代码不是 VBScript。如果这是一个 VBScript 问题 edit 它并显示您的 VBScript 代码。

标签: outlook fonts vbscript html-email office-automation


【解决方案1】:

The Outlook object model doesn't provide any default font properties like shown in the code sample. Instead, you can use the HTML markup to specify a custom font for the message body. For example:

olReply.HTMLBody = "<p style='font-family:'Segoe UI'><p style='font-size:11px'>Hello, <p> The individuals(s) in the email below have been submitted to the customer today, " & strDate & olReply.HTMLBody

Or just use the Word object model like shown in the following sample VBA code:

Public WithEvents objInspectors As Outlook.Inspectors
Public WithEvents objInspector As Outlook.Inspector

Public Sub Application_Startup()
    Set objInspectors = Outlook.Application.Inspectors
End Sub

Public Sub objInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
    Set objInspector = Inspector
End Sub

Public Sub objInspector_Activate()
    Dim objCurrentItem As Object
    Dim objCurrentInspector As Outlook.Inspector
    Dim objWordDocument As Word.Document
    Dim objWordSelection As Word.Selection
 
    Set objCurrentItem = objInspector.CurrentItem
    Set objCurrentInspector = objCurrentItem.GetInspector
    Set objWordDocument = objCurrentInspector.WordEditor
    Set objWordSelection = objWordDocument.Application.Selection
 
    'You change the font as per your preference
    Select Case objCurrentItem.Class
           Case olContact
                With objWordSelection.Font
                     .Name = "Segoe Script"
                     .ColorIndex = wdRed
                     .Size = 8
                     .Bold = True
                End With
           Case olAppointment
                With objWordSelection.Font
                     .Name = "Comic Sans MS"
                     .ColorIndex = wdBlue
                     .Size = 9
                     .Bold = False
                End With
           Case olTask
                With objWordSelection.Font
                     .Name = "MV Boli"
                     .ColorIndex = wdGreen
                     .Size = 10
                     .Bold = True
                End With
   End Select
End Sub

The Inspector.WordEditor property returns the Microsoft Word Document Object Model of the message being displayed.

  • I see, it seems like I may not have enough VB Script knowledge to understand the code above. However, as per the previous comment in the question, I think the syntax with **** As **** may not work. As per the HTLM custom font, do you have a resource for this? What I'm trying to create is an Outlook 2016 font change upon double-clinking a VB script. This will cover even the font of the existing emails like when it was initially formatted in Arial, it would change to TNR or any other. Thanks for the help btw.
  • Also sir, I want to ask if how do you run this file and test if it's successful?
  • The code posted was checked in VBA, so it has some minor syntax differences. I bet you can change these changes and adapt the code to the vbscript environment because the Outlook object model is common for all kind of programming languages.
  • You can debug and test the code in VBA prior getting it running in VBScript.
  • I tried your suggestion and tried to convert it to a VBScript. However, it still do not work even if I have an open Outlook 2016 instance. As per the HTML body font change, I have no experience with VBA to understand how to implement this script unfotunately. Thanks for the help anyways. I'm trying to figure out how to automatically do this with other programming languages.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多