急求:如何在Excel2007中利用VBA实现将选中区域的中文字体改成黑体,英文字体和数字改成Arial

2024-11-21 14:09:16
推荐回答(4个)
回答(1):

把原有的代码做一个修改,把活动单元格(With ActiveCell)变成所选范围袭差(With Selection)。你在滑誉执行下面的按钮的之前信禅段,选择要更改的范围,即可
Private Sub CommandButton1_Click()

Dim str As String
Dim i As Integer
str = ActiveCell

' With ActiveCell
With Selection

For i = 1 To Len(str)
If Asc(Mid(str, i, 1)) < 0 Then
.Characters(i, 1).Font.Name = "黑体"
Else
.Characters(i, 1).Font.Name = "Arial"
End If
Next i

End With

End Sub

回答(2):

还用那么复杂吗?
先将选中区域设置为汉字字体,如“仿宋”,再选中区域,笑信脊设置英文字体“Arial”就可以了啊,汉字按汉字字体显示,坦答英文、数字碰渗按Arial显示

回答(3):

Sub aa()
Dim str As String
Dim i As Integer
Dim a As Range

Set a = Range("穗羡a1:a10") '选择的范围

For Each b In a
str = b.Cells
For i = 1 To Len(str)
If Asc(Mid(str, i, 1)) < 0 Then
b.Cells.Font.Name = "黑体"
Else
b.Cells.Font.Name = "猜枝拍搭雹Arial"
End If
Next i
Next
End Sub

回答(4):

复制改好的格,选择性粘贴 格式 到其他要改的单元格即可