zjg121 发表于 2024-5-19 17:07

wordvba:写入密度

在word文件中写入带格式的密度表达式。


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


https://imgsrc.baidu.com/forum/pic/item/dcc451da81cb39db597cf76b96160924ab18304b.jpg

hrwcn 发表于 2024-5-25 15:28

很好,谢谢分享!

lizhibobo521 发表于 2024-6-19 20:42

终于找到大哥了   大哥VX多少我需要您的帮助

1e3e 发表于 2024-6-20 09:19

谢谢分享真心很厉害
页: [1]
查看完整版本: wordvba:写入密度