BlueDNA
04-20-2006, 04:54 PM
Hi all,
Can someone tell me Excel's equivalent to:
Dim strResult As String
Dim fileName As String
fileName = "C:\config.ini"
strResult = WordBasic.[GetPrivateProfileString$]("Username", "Name", fileName)
I would like to create a config file and would like to use a similar method (predefined tags) instead of reading the whole file.
Is this even possible? :dunno
Thanks in advance for any help or suggestions!
David
Edit:
Ive found a Windows API that does this, but im having difficulty getting it to work. The file exists, but the section and key fail. Therefore the default value is always returned instead.
Option Explicit
#If Win32 Then
Private Declare Function GetPrivateProfileString Lib _
"kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, lpKeyName As Any, ByVal _
lpDefault As String, ByVal lpRetStr As String, ByVal nSize _
As Long, ByVal lpFileName$) As Long
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As Any, _
ByVal lpWindowName As Any) As Long
Private Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd&, _
ByVal nCmdShow As Long) As Long
#Else
Private Declare Function GetPrivateProfileString Lib "Kernel" _
(ByVal lpAppName$, ByVal lpKeyName$, ByVal lpDefault$, _
ByVal lpReturnStr$, ByVal nSize%, ByVal lpFileName$) _
As Integer
Private Declare Function FindWindow Lib "User" _
(ByVal lpClassName$, ByVal lpWindowName As Long) As Integer
Private Declare Function PostMessage Lib "User" (ByVal hWnd%, _
ByVal wMsg As Integer, ByVal wParam%, lParam&) As Long
Private Declare Function ShowWindow Lib "User" _
(ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer
#End If
Public Function GetINI(ByVal Section$, ByVal Key$, ByVal _
Default$, ByVal FileName$) As String Dim res%, retVal$
retVal = Space$(32400)
res = GetPrivateProfileString(Section, Key, Default, _ retVal, Len(retVal), FileName)
GetINI = Left$(retVal, res)
End Function
This is what im trying:
Dim configFile As String
Dim strResult As String
configFile = "C:\config.ini"
strResult = GetINI("Username", "Name", "Not Found", configFile)
MsgBox strResult
Any ideas?
Can someone tell me Excel's equivalent to:
Dim strResult As String
Dim fileName As String
fileName = "C:\config.ini"
strResult = WordBasic.[GetPrivateProfileString$]("Username", "Name", fileName)
I would like to create a config file and would like to use a similar method (predefined tags) instead of reading the whole file.
Is this even possible? :dunno
Thanks in advance for any help or suggestions!
David
Edit:
Ive found a Windows API that does this, but im having difficulty getting it to work. The file exists, but the section and key fail. Therefore the default value is always returned instead.
Option Explicit
#If Win32 Then
Private Declare Function GetPrivateProfileString Lib _
"kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, lpKeyName As Any, ByVal _
lpDefault As String, ByVal lpRetStr As String, ByVal nSize _
As Long, ByVal lpFileName$) As Long
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As Any, _
ByVal lpWindowName As Any) As Long
Private Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd&, _
ByVal nCmdShow As Long) As Long
#Else
Private Declare Function GetPrivateProfileString Lib "Kernel" _
(ByVal lpAppName$, ByVal lpKeyName$, ByVal lpDefault$, _
ByVal lpReturnStr$, ByVal nSize%, ByVal lpFileName$) _
As Integer
Private Declare Function FindWindow Lib "User" _
(ByVal lpClassName$, ByVal lpWindowName As Long) As Integer
Private Declare Function PostMessage Lib "User" (ByVal hWnd%, _
ByVal wMsg As Integer, ByVal wParam%, lParam&) As Long
Private Declare Function ShowWindow Lib "User" _
(ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer
#End If
Public Function GetINI(ByVal Section$, ByVal Key$, ByVal _
Default$, ByVal FileName$) As String Dim res%, retVal$
retVal = Space$(32400)
res = GetPrivateProfileString(Section, Key, Default, _ retVal, Len(retVal), FileName)
GetINI = Left$(retVal, res)
End Function
This is what im trying:
Dim configFile As String
Dim strResult As String
configFile = "C:\config.ini"
strResult = GetINI("Username", "Name", "Not Found", configFile)
MsgBox strResult
Any ideas?