在word文件中写入带格式的密度表达式。
[Visual Basic] 纯文本查看 复制代码 Sub 宏1()
'
' 宏1 宏
'
'
rho ("水")
rho ("酒精")
rho ("煤油")
rho ("铜")
rho ("铁")
rho ("钢")
rho ("铝")
rho ("石")
rho ("水银")
End Sub
Function rho(substance As String)
'
' 密度
'
'
Selection.InsertSymbol Font:="+西文正文", CharacterNumber:=961, Unicode:=True
Selection.Text = substance
Selection.Font.Subscript = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Font.Subscript = wdToggle
Selection.TypeText Text:="="
If substance = "水" Then
zhi = "1.0"
ElseIf substance = "酒精" Or substance = "煤油" Then
zhi = "0.8"
ElseIf substance = "水银" Then
zhi = "13.6"
ElseIf substance = "铜" Then
zhi = "8.9"
ElseIf substance = "铁" Or substance = "钢" Then
zhi = "7.9"
ElseIf substance = "铝" Or substance = "石" Then
zhi = "2.7"
End If
Selection.TypeText Text:=zhi
Selection.TypeText Text:=ChrW(&HD7) & "103"
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Superscript = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Font.Superscript = wdToggle
Selection.TypeText Text:="kg/m3"
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Superscript = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Font.Superscript = wdToggle
Selection.TypeText Text:=" "
Selection.TypeText Text:=vbCrLf
End Function
|