vba - 更改字符中的语言 ID
问题描述
我有一个 word 文档,其中一些字符(如“[”)在 lang.charaters LanguageID=2057 和一些 LanguageID=1037
我试图通过以下代码更改它:
For Each oChr In pRange.Characters
If oChr.LanguageID = 2057 Then
oChr.LanguageID = 1037
End If
Loop Until pRange Is Nothing
但分配后 LanguageID 没有改变
为什么 ?我怎样才能让它工作?
解决方案
这是我不久前编写的一个更改校对语言的程序。
您是正确的,可以将校对语言属性应用于字符,但您无需检查每个字符即可重置。以下检查文档的所有故事并设置校对语言。您可以将常量更改为您想要的,而不是 EnglishUS。
Sub ProofingLanguageEnglishUSAllStory() ' based on field updater by Greg Maxey
' https://gregmaxey.com/word_tip_pages/word_fields.html
' Charles Kenyon 6 November 2018
' https://answers.microsoft.com/en-us/msoffice/forum/all/force-all-documents-to-be-edited-in-uk-english/df6d1f8e-5426-49d9-bea0-5620d0208294
' Changes proofing language to English US in all stories of document
' Language IDs https://docs.microsoft.com/en-us/office/vba/api/word.wdlanguageid
Dim rngStory As Word.range
Dim lngValidate As Long ' do not know purpose of this
Dim oShp As Shape
lngValidate = ActiveDocument.Sections(1).Headers(1).range.StoryType
For Each rngStory In ActiveDocument.StoryRanges
'Iterate through all linked stories
Do
On Error Resume Next
rngStory.LanguageID = wdEnglishUS ' delete or comment out if you do not want to change the language ID
rngStory.NoProofing = False Select Case rngStory.StoryType
Case 6, 7, 8, 9, 10, 11
If rngStory.ShapeRange.Count > 0 Then
For Each oShp In rngStory.ShapeRange
If oShp.TextFrame.HasText Then
' Comment out or delete the next line if you do not want to change proofing language
oShp.TextFrame.TextRange.LanguageID = wdEnglishUS ' delete or comment out if you do not want to change the language ID
' Comment out or delete the next line if you do not want to change the "no proofing" setting
oShp.TextFrame.TextRange.NoProofing = False
End If
Next
End If
Case Else
'Do Nothing
End Select
On Error GoTo -1
'Get next linked story (if any)
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next
End Sub
这是页面上处理不同问题的三个宏之一。宏使用 Word 常量作为语言 ID,而不是数字等价物。这是我在 Microsoft Answers 网站上关于以下主题的文章:修复校对语言问题。
推荐阅读
- javascript - 在角度 8 中通过引用调用组件数组属性
- python - 如何在 .scss 文件中使用来自后端的变量
- mysql - PHP MySQL如何计算行之间的距离?
- powershell - Powershell脚本在DeploymentType中创建注册表检测方法
- c++ - c++ 中的 string a="hello" 和 string a=(char *)"hello" 有什么区别?
- ios - 自定义 VC 转换未正确关闭
- asp.net - WCF,Mtom 消息编码,已超出传入消息的最大消息大小配额 (65536)
- python - 使用 PyOpenGL 创建 GL_GEOMETRY_SHADER 时出错
- grpc - Tensorflow serving(docker):如何获取客户端发送的grpc请求日志?
- c - 为什么 strcmp 似乎不适用于 strtok 返回的字符串?