Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft Word and Excel 11.0 Object Library ekreider Excel Discussion (Misc queries) 4 January 8th 08 04:01 PM
Microsoft Word Object Library in Excel Gaetan Excel Discussion (Misc queries) 4 March 14th 07 06:34 PM
VB Error Object Library Not Registered Karine Rivet Excel Discussion (Misc queries) 2 April 11th 06 07:13 PM
Excel 11.0 Object Library Al Excel Programming 2 November 12th 04 04:32 PM
Printing through the Excel Object Library Shay Friedman Excel Programming 1 September 23rd 03 03:22 AM


All times are GMT +1. The time now is 01:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"