Excel VBA is equivalent to Word VBA

I have a Word VBA function that I'm trying to create in Excel VBA (the reason for this choice comes from this question ), and I'm stuck with the following problem:

The Word VBA function is widely used System.PrivateProfileString, which throws an error Compile Error: invalid qualifierwhen applied to Excel VBA. What is the equivalent instruction in Excel? Alternatively, how do I do this?

Usage example:

strHomeSharePath = System.PrivateProfileString("", "HKEY_CURRENT_USER\Volatile Environment", "HOMESHARE")
+4
source share
2 answers

Hi, if you want to read registerability in Excel, you can do it this way.

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
+3
source

( ) Excel Object, , "objWord", ...

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

IMO "" , , Word. Word.

+1

Source: https://habr.com/ru/post/1626146/


All Articles