【发布时间】:2015-07-02 14:49:46
【问题描述】:
我的一个脚本有问题。 我将一个 Public-Sub 例程注入用户 Normal.dotm(注入“ThisDocument”)。 该脚本工作正常,但只有一个客户端。 (在它不起作用的客户端上,Word Process 正在崩溃,见下文......) 如果有经验的程序员可以看看我的编码,或者告诉我如何调试出了什么问题,我会很好。 所有变量均已正确填写,并且客户端都是具有相同策略的 Win7 Enterprise。 normal.dotm 也在每台机器上的相同位置。 • 在所有客户端上都设置了“对 VBA 项目对象模型的信任访问”。
有什么想法吗?
这是完整的代码:
' 22.04.2015
' Imports the CRM WordMerge Function into the Normal.dot
' Homefolder als Variable bereitstellen
Set oShell = CreateObject("WScript.Shell")
strHomeFolder = oShell.ExpandEnvironmentStrings("%APPDATA%")
' wscript.echo strHomeFolder
' Auslesen des aktuellen Verzeichnisspfades
scriptdir = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
' WScript.Echo scriptdir
' Get current User
Set objNetwork = CreateObject("Wscript.Network")
' Backup der Originalen Normal.dotm
dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
' Existierendes Backup löschen
If filesys.FolderExists(scriptdir & "\Backup\" & objNetwork.UserName) Then
filesys.DeleteFolder scriptdir & "\Backup\" & objNetwork.UserName
end if
' File mit Pfad zur normal.dotm einlesen:
strdatei=scriptdir & "\Path\path.txt"
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTest = objFSO.GetFile(strdatei)
If objTest.Size > 0 Then
Set objFile = objFSO.OpenTextFile(strdatei, ForReading)
strText = objFile.ReadAll
strText = oShell.ExpandEnvironmentStrings(strText)
'wscript.echo strText
objFile.Close
end if
If filesys.FileExists(strText) Then
' MsgBox(scriptdir & "\Backup\" & objNetwork.UserName)
filesys.CreateFolder scriptdir & "\Backup\" & objNetwork.UserName
filesys.CopyFile strText, scriptdir & "\Backup\" & objNetwork.UserName & "\"
end if
const wdDoNotSaveChanges = 0
WScript.Echo "Installing FrNow Macro for Word..."
' Dim oApplication, doc
Dim oApplication, doc
Set oApplication = CreateObject("Word.Application")
' WScript.Echo "Opening Normal.dot Template..."
oApplication.Documents.Open strText
Set doc = oApplication.ActiveDocument
Dim comp, components
Set components = oApplication.ActiveDocument.VBProject.VBComponents
' Importiere CRM Makro
oApplication.ActiveDocument.VBProject.VBComponents("ThisDocument").CodeModule.AddFromFile(scriptdir & "\Import\FrNow.cls")
WScript.Echo "Installation Finished..."
doc.close wdDoNotSaveChanges
oApplication.Quit wdDoNotSaveChanges
【问题讨论】:
-
我认为让您访问
VBProject的参数是您需要手动检查Office参数才能使用您的代码 -
您能否详细解释一下,我该如何检查 - 我在这一行中看不到任何客户特定的内容?
-
详细信息在我下面的回答中,我在回答中的评论中添加了另一个可能对您有所帮助的线索
标签: vba vbscript scripting ms-word