World-宏函数将内容中的英文引号(')全部改成中文的引号(”)

World-宏函数将内容中的英文引号(')全部改成中文的引号(”)

一、文件 - 选项 - 信任中心 - 信任中心设置

image

二、勾选启用宏 & 开发人员设置

image

三、Alt + F11

插入- 模块

image

粘贴以下内容

Sub ReplaceSingleQuotesWithChineseQuotes()
	Dim doc As Document
	Dim rng As Range
	Dim inQuotes As Boolean

	Set doc = ActiveDocument
	Set rng = doc.Content
	inQuotes = False

	' 遍历整个文档
	With rng.Find
		.ClearFormatting
		.text = "'"
		.Forward = True
		.Wrap = wdFindStop
		.MatchWildcards = False

		Do While .Execute
			If inQuotes Then
				' 替换为右引号(”)
				rng.text = "”"
				inQuotes = False
			Else
				' 替换为左引号(“)
				rng.text = "“"
				inQuotes = True
			End If

			' 继续查找下一个
			rng.Collapse Direction:=wdCollapseEnd
		Loop
	End With

	MsgBox "英文单引号已替换为中文双引号!", vbInformation
End Sub

四、Alt + F8 点击运行

image

posted @ 2025-06-16 16:18  skystrivegao  阅读(42)  评论(0)    收藏  举报