vba - Excel VBA 相当于 Word VBA 系统

标签 vba excel ms-word

我有一个 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/

相关文章:

vba - 使用 Selenium Basic (VBA) 循环访问一组页面

vba - 使用一行代码清除范围数组

excel - MSEXCEL 将数据转置为数据库格式

vba - 更快的 VBA 隐藏行

delphi - 将格式化文本从 Word 文档表格的单元格复制到 RichEdit

excel - VBA 初学者 : Greater than

vba - 使用 VBA 中的表格生成完全格式化的电子邮件

excel - Office Excel平均函数: what's the difference between AVERAGE(A2:C2 B1:B10) and AVERAGE(A2:C2, B1 :B10)?

vba - 删除 Word 字段 VBA 在 Word 2013 中不起作用,在 Word 2010 中起作用

java - 是否可以使用 Apache POI 解析 MS Word 并将其转换为 XML?