Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error using Word object library in Excel (VBA)
I need to use the PrivateProfileString() function contained within the
'System' object to read/write an .ini file. I have referenced the relevant Word object library to Excel but the function only works whilst Word is open. I get the following (common) error: Run-time Error 429; ActiveX component can't create object. Can I actually read/write an .ini file using VBA in Excel? Would be greatful for any help. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error using Word object library in Excel (VBA)
Luke,
VBA does not have a "System" object. If you are something .Net, that's another thing. Anyway, try: http://www.exceltip.com/st/Private_P...iles_using_VBA _in_Microsoft_Excel/490.html NickHK "LukeCarvey" wrote in message ... I need to use the PrivateProfileString() function contained within the 'System' object to read/write an .ini file. I have referenced the relevant Word object library to Excel but the function only works whilst Word is open. I get the following (common) error: Run-time Error 429; ActiveX component can't create object. Can I actually read/write an .ini file using VBA in Excel? Would be greatful for any help. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error using Word object library in Excel (VBA)
You can use APIs in Excel
Private Declare Function GetPrivateProfileInt Lib "kernel32" _ Alias "GetPrivateProfileIntA" _ (ByVal lpApplicationName As String, _ ByVal lpKeyName As String, _ ByVal nDefault As Long, _ ByVal lpFileName As String) As Long Private Declare Function GetPrivateProfileString Lib "kernel32" _ Alias "GetPrivateProfileStringA" _ (ByVal lpApplicationName As String, _ ByVal lpKeyName As Any, _ ByVal lpDefault As String, _ ByVal lpReturnedString As String, _ ByVal nSize As Long, _ ByVal lpFileName As String) As Long Private Declare Function WritePrivateProfileString Lib "kernel32" _ Alias "WritePrivateProfileStringA" _ (ByVal lpApplicationName As String, _ ByVal lpKeyName As Any, _ ByVal lpString As Any, _ ByVal lpFileName As String) As Long and use like so cSubItems = GetPrivateProfileInt("myApp", "Id", 0, Filename) and Dim sKeyValue As String Dim nLen As Long sKeyValue = Space$(255) nLen = GetPrivateProfileString(AppId, K"myApp","Id", "Not Found", _ sKeyValue, Len(sKeyValue), Filename) If nLen = Len(sKeyValue) - 1 Then 'means sKeyValue not long enough sKeyValue = Space$(Len(sKeyValue) + 100) Else sKeyValue = Left(sKeyValue, nLen) End If -- HTH RP (remove nothere from the email address if mailing direct) "NickHK" wrote in message ... Luke, VBA does not have a "System" object. If you are something .Net, that's another thing. Anyway, try: http://www.exceltip.com/st/Private_P...iles_using_VBA _in_Microsoft_Excel/490.html NickHK "LukeCarvey" wrote in message ... I need to use the PrivateProfileString() function contained within the 'System' object to read/write an .ini file. I have referenced the relevant Word object library to Excel but the function only works whilst Word is open. I get the following (common) error: Run-time Error 429; ActiveX component can't create object. Can I actually read/write an .ini file using VBA in Excel? Would be greatful for any help. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error using Word object library in Excel (VBA)
You can read fromINI files with this:
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long sub xx() Ret = String(255, 0) Length = GetPrivateProfileString(App.Title, "KeyName", "Default", Ret, 255, "C:\myfile.ini") Ret = Left$(Ret, Length) ' assumes Length<0 end Sub "LukeCarvey" wrote: I need to use the PrivateProfileString() function contained within the 'System' object to read/write an .ini file. I have referenced the relevant Word object library to Excel but the function only works whilst Word is open. I get the following (common) error: Run-time Error 429; ActiveX component can't create object. Can I actually read/write an .ini file using VBA in Excel? Would be greatful for any help. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Microsoft Word and Excel 11.0 Object Library | Excel Discussion (Misc queries) | |||
Microsoft Word Object Library in Excel | Excel Discussion (Misc queries) | |||
VB Error Object Library Not Registered | Excel Discussion (Misc queries) | |||
Excel 11.0 Object Library | Excel Programming | |||
Printing through the Excel Object Library | Excel Programming |