嗨,Mark,
我在VBScript中尝试的线程中发布的代码**LINK**是我在VBA中使用的示例。只需确保转到工具>引用并添加对“Windows脚本主机对象模型”的引用
,然后就可以了:
Sub SheetSetTemplatePath_WORKING()
Dim WshShell As New WshShell
Dim curver, locale, cprofile
Dim vname '= Value Name
Dim vdata '= Value Data
'Set WshShell = WScript.CreateObject("WScript.Shell")
'Set WshNetwork = WScript.CreateObject("WScript.Network")
vname = "SheetSetTemplatePath"
'This reads the currently installed and last accesed version of AutoCAD
curver = WshShell.RegRead("HKCU\Software\Autodesk\AutoCAD\curver")
'There is an additional value under that registry key, it is unique and must be grabbed from here, or else you won't know the location of the profile
locale = WshShell.RegRead("HKCU\Software\Autodesk\AutoCAD" & curver & "\curver")
'This Key holds only the current profile
cprofile = WshShell.RegRead("HKCU\Software\Autodesk\AutoCAD" & curver & "" & locale & "\Profiles")
'New Path Goes Here
vdata = "I:\Path\Template"
'Write The VName and VData (Support Path)
WshShell.RegWrite "HKCU\Software\Autodesk\AutoCAD" & curver & "" & locale & "\Profiles" & _
cprofile & "\General" & vname, vdata
'Return the results:
'MsgBox "The Path for " & vname & vbCrLf & vdata & vbCrLf & "has been written to" & vbCrLf & _
'"AutoCAD - " & curver & "," & vbCrLf & "Profile - " & cprofile
End Sub