我正在尝试通过VBA写入注册表的路径
这段代码在VBScript中运行得很好,但我想将其合并到我的VBA模块中(如果可能的话)
如果有人知道如何使下面的代码在VBA中工作,我将不胜感激
或者,如果是(通过VBA)将支持路径写入注册表的替代方法,我真的很想知道该方法,谢谢
- Sub SheetSetTemplatePath_NOT_WORKING()
- Dim WshShell, WshNetwork As Object
- 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
|