Excel VBA 相当于 Word VBA 系统

Hol*_*ene 5 excel vba ms-word

我有一个 Word VBA 函数,我正在尝试在 Excel VBA 中构建它(这个选择背后的原因来自这个问题),但我遇到了以下问题:

Word VBA 函数使用System.PrivateProfileString广泛,Compile Error: invalid qualifier应用于 Excel VBA 时会引发错误。Excel 中的等效语句是什么?或者,我该如何解决这个问题?

使用示例:

strHomeSharePath = System.PrivateProfileString("", "HKEY_CURRENT_USER\Volatile Environment", "HOMESHARE")
Run Code Online (Sandbox Code Playgroud)

Moo*_*sli 4

如果您想在 Excel 中读取注册表,可以这样做。

Sub test()
Dim strPath As String
    strPath = RegKeyRead("HKEY_CURRENT_USER\Volatile Environment\HOMESHARE")
End Sub

Function RegKeyRead(i_RegKey As String) As String
Dim myWS As Object

  On Error Resume Next
  'access Windows scripting
  Set myWS = CreateObject("WScript.Shell")
  'read key from registry
  RegKeyRead = myWS.RegRead(i_RegKey)
End Function
Run Code Online (Sandbox Code Playgroud)