微软vbscript下载_使用VBScript更新或添加到Microsoft的custom.dic

微软vbscript下载

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question

不久前,我在VB Script论坛中看到一个问题,我认为不会花太多时间。 您可以阅读该问题

(Question ID  (问题ID 28455246) Here. The asker wanted some help getting a script to update the custom.dic file for dictionary values in Microsoft Office. I thought no problem, it is just a text file. So I took a look at the code and it looked fine, but then I tried to run it and got the same error. I thought, well, that is strange, it is just a simple text file. Oh, but it is not. 28455246)在这里 。 询问者希望获得帮助,以获取脚本来更新Microsoft Office中字典值的custom.dic文件。 我以为没问题,这只是一个文本文件。 所以我看了一下代码,看起来还不错,但是后来我尝试运行它,并得到了同样的错误。 我认为,这很奇怪,它只是一个简单的文本文件。 哦,但是不是。

When I opened it in Notepad++ I found that the encoding was not the standard utf-8, but rather it showed as UCS-2 Little Endian. I figured it cannot be that hard to write a script to update this file, so I took a whack at it. Needless to say after much searching in the internet and much more time than I had planned to spend on the question, I had nothing. That never feels good.

当我在Notepad ++中打开它时,我发现编码不是标准的utf-8,而是显示为UCS-2 Little Endian。 我认为编写脚本来更新该文件并不难,所以我对此大吃一惊。 不用说,在互联网上进行了大量搜索并且花费了比我计划在该问题上花费的时间更多的时间,我一无所有。 感觉永远不好。

I took a break for the day and came back the next morning. Several ideas I found that should work did not. I had headed down the path of opening the file, saving it as UTF-8, and then opening it again and saving it back out. I found some scripts that could do that process, but all failed when I tried to add text. Eventually I stumbled across the right combination and sequence.

我休息了一天,第二天早上回来。 我发现应该可行的一些想法没有用。 我已经走过打开文件的路径,将其保存为UTF-8,然后再次将其打开并保存回去。 我发现一些脚本可以执行该过程,但是当我尝试添加文本时所有脚本都失败了。 最终,我偶然发现了正确的组合和顺序。

I decided since all the scripts on the internet that I could find to update MS Office’s dictionary assumed the older style file that was UTF-8, I needed to publish what I had found so others would not waste their time as I did.

我决定,因为我可以找到的用于更新MS Office词典的所有Internet脚本都假定使用的是较旧的样式文件UTF-8,所以我需要发布自己发现的内容,以便其他人不会像我那样浪费时间。

First, in my script I wanted to account for the location of the file as Microsoft moved it between versions. I added that into my code. Once I find the file, the concept that worked for me was to open the file using the ADO stream with the Unicode character set. I then update the text and save it off as UTF-8 with the ADO Stream.

首先,在脚本中,我想考虑文件的位置,因为Microsoft在两个版本之间移动了它。 我将其添加到我的代码中。 找到文件后,对我有用的概念是使用带有Unicode字符集的ADO流打开文件。 然后,我更新文本并将其与ADO Stream一起另存为UTF-8。

That way the new text and the old text all have the same encoding at that point. Now here you would think I could just convert the stream to UTF-8, add the text, convert it back and save it with the ADO stream, but I could never get that to work. I ended up saving it as a temp file with the UTF-8 encoding.

这样,新文本和旧文本在那时都具有相同的编码。 现在在这里您会认为我可以将流转换为UTF-8,添加文本,将其转换回并使用ADO流保存,但是我永远无法使它正常工作。 我最终将其保存为具有UTF-8编码的临时文件。

Now I have to get this back to Unicode. Therefore I open the file up with the ADO stream again and this time write it back out with the File System Object using the Unicode flag. Now when I look at the dictionary my new words have been added and the file is in the correct encoding.

现在,我必须将其恢复为Unicode。 因此,我再次使用ADO流打开了文件,这次使用Unicode标志将其写回到文件系统对象中。 现在,当我查看字典时,已经添加了新词,并且文件的编码正确。

Now in the script, you have to tell it what words you want added to the custom dictionary.  You will need to update this code section in the full script:

现在,在脚本中,您必须告诉它要添加到自定义词典中的单词。 您将需要在完整脚本中更新此代码部分:

'**************************************
' Add Your Text That is to be inserted into the Dictionary
'**************************************
strText = objOriginalFile.ReadText
strText = strText  & "Test1" & vbcrlf
strText = strText  & "Test2" & vbcrlf
'**************************************
strText = Replace(strText, "WordToReplace" & vbcrlf, "")
' ExpertExchange 
' Expert: ltlbearand3 [http://www.experts-exchange.com/M_2469312.html]
'
' Add a value or values to Microsoft's Custom.Dic via script
' The file encoded in UCS-2 Little Endian (according to notepad++)
' Must open the file convert to UTF-8, add your words, and convert back

Option Explicit
' --------------------------------------------------------------------------------
'  Set Up Variables, Define Constants and Instantiate objects
' --------------------------------------------------------------------------------
Dim objFSO, objOriginalFile, objTempFile, objNetwork, objNewFile, objShell
Dim strPath1, strPath2, strFile, strTempFile, strText

' Set Constants
Const adTypeText   = 2   
Const adSaveCreateOverWrite = 2
Const ForWriting = 2
Const TristateTrue = -1 'Opens Files as Unicode
Const DICTIONARYNAME = "CUSTOM.DIC"

' Instantiate Objects
Set objNetwork = CreateObject("WScript.Network")
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set objShell = CreateObject("WScript.Shell")
Set objOriginalFile = CreateObject("ADODB.Stream")  
Set objTempFile = CreateObject("ADODB.Stream")
Set objNewFile = CreateObject("ADODB.Stream")  

' --------------------------------------------------------------------------------
'  Set up the File Location (Microsoft Office moves this file around based on version)
' --------------------------------------------------------------------------------
' Set Values for possible file location based on MS Office Version
strPath1 = "C:\Users\" & objNetwork.UserName & "\AppData\Roaming\Microsoft\Spelling\en-US\"
strPath2 = "C:\Users\" & objNetwork.UserName & "\AppData\Roaming\Microsoft\UProof\"

' Find the location of the Dictionary file as it changes based on version
If objFSO.FileExists (strPath1 & DICTIONARYNAME) Then
	strFile = strPath1 & DICTIONARYNAME
ElseIf objFSO.FileExists (strPath2 & DICTIONARYNAME) Then
	strFile = strPath2 & DICTIONARYNAME
Else
	Wscript.Echo DICTIONARYNAME & " was not found."
	wcript.quit
End If

' Set Temp File
strTempFile = objShell.ExpandEnvironmentStrings("%TEMP%") & "\" & "TempDictionary.Dic"

' --------------------------------------------------------------------------------
' Open in ADO Stream to convert to UTF-8 and save in Temp File
' --------------------------------------------------------------------------------
' Open original File
objOriginalFile.Type = adTypeText
objOriginalFile.Charset = "unicode"
objOriginalFile.open
objOriginalFile.LoadFromFile strFile

'**************************************
'**************************************
' Add Your Text That is to be inserted into the Dictionary
'**************************************
strText = objOriginalFile.ReadText
strText = strText  & "Test1" & vbcrlf 
strText = strText  & "Test2" & vbcrlf
'**************************************
'**************************************

' Save as UTF-8 File
objTempFile.Type = adTypeText   
objTempFile.Charset = "utf-8"
objTempFile.Open 
objTempFile.WriteText strText
objTempFile.SaveToFile strTempFile, adSaveCreateOverWrite

' Close the Files
objOriginalFile.Close
objTempFile.Close

' --------------------------------------------------------------------------------
' Now Open the UTF-8 file and use the File System Object to save it back as Unicode(UCS-2 Little Endian)
' --------------------------------------------------------------------------------
objNewFile.Type = adTypeText
objNewFile.Charset = "utf-8"
objNewFile.Open
objNewFile.LoadFromFile strTempFile
objFSO.OpenTextFile(strFile, ForWriting, True, TristateTrue).Write objNewFile.ReadText
objNewFile.Close

' --------------------------------------------------------------------------------
' Clean Up
' --------------------------------------------------------------------------------
Set objFSO = Nothing
Set objNetwork = Nothing
Set objNewFile = Nothing
Set objOriginalFile = Nothing
Set objTempFile = Nothing

Wscript.Echo strFile & " has been updated."

翻译自: https://www.experts-exchange.com/articles/14075/Using-VBScript-to-Update-or-Add-To-Microsoft's-custom-dic.html

微软vbscript下载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
什么是 VBScriptMicrosoft Visual Basic Scripting Edition 是程序开发语言 Visual Basic 家族的最新成员,它将灵活的脚本应用于更广泛的领域,包括 Microsoft Internet Explorer 中的 Web 客户机脚本和 Microsoft Internet Information Service 中的 Web 服务器脚本。 易学易用 如果您已了解 Visual Basic 或 Visual Basic for Applications,就会很快熟悉 VBScript。即使您没有学过 Visual Basic,只要学会 VBScript,就能够使用所有的 Visual Basic 语言进行程序设计。虽然您可以从本教程的几个 Web 页面中学习 VBscript,但是本教程并没有告诉您如何编程。要学习编程,请阅读由 Microsoft Press 出版的《Step by Step》。 ActiveX 脚本 VBScript 使用 ActiveX(R)脚本与宿主应用程序对话。使用 ActiveX Script,浏览器和其他宿主应用程序不再需要每个脚本部件的特殊集成代码。ActiveX脚本使宿主可以编译 Script、获取和调用入口点及管理开发者可用的命名空间。通过 ActiveX Script,语言厂商可以建立标准脚本运行时语言。Microsoft 将提供 VBScript 的运行时支持。Microsoft 正在与多个 Internet 组一起定义 ActiveX脚本标准以使脚本引擎可以互换。ActiveX脚本可用在 Microsoft(R) Internet Explorer 和 Microsoft(R) Internet Information Service 中。 其他应用程序和浏览器中的 VBScript 作为开发者,您可以在您的产品中免费使用 VBScript 源实现程序。Microsoft 为 32 位 Windows(R) API、16 位 Windows API 和 Macintosh(R) 提供 VBscript 的二进制实现程序。VBScript 与 World Wide Web 浏览器集成在一起。VBScript 和 ActiveX脚本也可以在其他应用程序中作为普通脚本语言使用

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值