将表格的特定部分加粗

时间:2018-12-19 16:14:43

标签: vba ms-word

我更改了用于自动粘贴基于AD的Outlook签名的脚本的代码。现在我在使格式化工作方面遇到一些问题

我有一个包含大多数有用信息的单元格,但是我需要名字和姓氏加粗。而其他信息则位于同一行及其下方,以遵循其上方给出的格式信息

我尝试将代码分隔在不同的单元格中,但是格式全部错误

objTable.Cell(1, 2).Range.Text = strFirstName & " " & strLastName & " | " & strTitle & Chr(11) & strDepartment & Chr (11) & Chr(11) & strAdress & ", " & strPostal &  " " & strCity & Chr (11) & "T" &  " " & strPhone & strTelefoon & Chr (11) & "E " & strEmail

strFirstName和strLastName应该为粗体

2 个答案:

答案 0 :(得分:0)

尝试:

With objTable.Cell(1, 2).Range
  .Text = strFirstName & " " & strLastName & " | " & strTitle & Chr(11) & _
  strDepartment & Chr(11) & Chr(11) & _
  strAdress & ", " & strPostal & " " & strCity & Chr(11) & _
  "T" & " " & strPhone & strTelefoon & Chr(11) & _
  "E " & strEmail
  .End = .Start + InStr(.Text, " | ") - 1
  .Font.Bold = True
End With

答案 1 :(得分:0)

感谢所有答案!

我通过选择.select

进行了修复
objTable.Cell(1,2).select
objSelection.Font.Name = "Calibri Light"
objSelection.Font.Size = "11"
objSelection.Font.Color = RGB(23,68,153)
If strFirstName <> "" Then
            objSelection.Font.Bold = True
            objSelection.TypeText strFirstName & " " & strLastName
            objSelection.Font.Bold = False
End If
If strTitle <> "" Then
    ObjSelection.TypeText " | " & strTitle 
End If
ObjSelection.TypeText (Chr(11))
ObjSelection.TypeText strDepartment 
ObjSelection.TypeText (Chr(11))
If strFirstName <> "" Then
            objSelection.Font.size = 5
            objSelection.TypeText " "
            objSelection.Font.size = 11
End If
ObjSelection.TypeText (Chr(11))
ObjSelection.TypeText strAdress & ", " & strPostal &  " " & strCity
ObjSelection.TypeText (Chr(11))
If strPhone <> "" Then
            objSelection.Font.Bold = True
            objSelection.TypeText "T " 
            objSelection.Font.Bold = False
End If
ObjSelection.TypeText strPhone 
If strGSM <> "" Then
            objSelection.TypeText " | " 
            objSelection.Font.Bold = True
            objSelection.TypeText " G " 
            objSelection.Font.Bold = False
End If
ObjSelection.TypeText strTelefoon 
ObjSelection.TypeText (Chr(11))
If strEmail <> "" Then
            objSelection.Font.Bold = True
            objSelection.TypeText "E " 
            objSelection.Font.Bold = False
            objSelection.TypeText strEmail
End If