gpt4 book ai didi

vba - Excel VBA 相当于 Word VBA 系统

转载 作者:行者123 更新时间:2023-12-02 10:42:50 24 4
gpt4 key购买 nike

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

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

使用示例:

strHomeSharePath = System.PrivateProfileString("", "HKEY_CURRENT_USER\Volatile Environment", "HOMESHARE")

最佳答案

如果您想在 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

关于vba - Excel VBA 相当于 Word VBA 系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35034169/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com