- 积分
- 1625
- 明经币
- 个
- 注册时间
- 2025-2-14
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|

楼主 |
发表于 2025-3-23 09:57:50
|
显示全部楼层
在word中使用的代码,用于选中部分的中英文标点符号互转 - Sub 标点英转中()
- Dim rng As Range
- Dim strText As String
-
- ' 获取当前选中的文本范围
- Set rng = Selection.Range
-
- strText = rng.Text
-
- ' 替换英文标点符号为中文标点符号
- strText = Replace(strText, ",", ",")
- strText = Replace(strText, ".", "。")
- strText = Replace(strText, "?", "?")
- strText = Replace(strText, "!", "!")
- strText = Replace(strText, ":", ":")
- strText = Replace(strText, ";", ";")
- strText = Replace(strText, "(", "(")
- strText = Replace(strText, ")", ")")
- ' 替换英文双引号为中文双引号
- Dim firstQuote As Boolean
- firstQuote = True
- Dim i As Integer
- For i = 1 To Len(strText)
- If Mid(strText, i, 1) = """" Then
- If firstQuote Then
- Mid(strText, i, 1) = "“"
- Else
- Mid(strText, i, 1) = "”"
- End If
- firstQuote = Not firstQuote
- End If
- Next i
- ' 替换英文单引号为中文单引号
- firstQuote = True
- For i = 1 To Len(strText)
- If Mid(strText, i, 1) = "'" Then
- If firstQuote Then
- Mid(strText, i, 1) = "‘"
- Else
- Mid(strText, i, 1) = "’"
- End If
- firstQuote = Not firstQuote
- End If
- Next i
-
- ' 将替换后的文本写回选中范围
- rng.Text = strText
- End Sub
- Sub 标点中转英()
- Dim rng As Range
- Dim strText As String
-
- ' 获取当前选中的文本范围
- Set rng = Selection.Range
-
- strText = rng.Text
-
- ' 替换中文标点符号为英文标点符号
- strText = Replace(strText, ",", ",")
- strText = Replace(strText, "。", ".")
- strText = Replace(strText, "?", "?")
- strText = Replace(strText, "!", "!")
- strText = Replace(strText, ":", ":")
- strText = Replace(strText, ";", ";")
- strText = Replace(strText, "(", "(")
- strText = Replace(strText, ")", ")")
- strText = Replace(strText, "“", """")
- strText = Replace(strText, "”", """")
- strText = Replace(strText, "‘", "'")
- strText = Replace(strText, "’", "'")
-
- ' 将替换后的文本写回选中范围
- rng.Text = strText
- End Sub
|
|