Write to text file - OK a admit defeat

birchs92

New Member
Joined
Nov 1, 2007
Messages
44
Dear All

I am using the code below to write "xxxx" to a text file (by way of a test)

Sub test()
Dim full As String
full = "xxxx"

' Declare a FileSystemObject.
Dim fso As New FileSystemObject

' Declare a TextStream.
Dim stream As TextStream

' Create a TextStream.
Set stream = fso.CreateTextFile("c:\string.log", True)

'write to file
stream.Write full

'close steam
stream.Close

End Sub

I have the 'Microsoft Scripting Runtime' reference ticked

Excel version - Excel 20017

Get error - "Automation error Library not registered"


Any ideas !!! Thanks in advance.. Simon
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
It sounds like you need to reregister the Scripting runtime library. Can you just test this late bound version:
Code:
Sub test()
Dim full As String 
full = "xxxx"

' Declare a FileSystemObject.
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
' Declare a TextStream.
Dim stream As Object

' Create a TextStream.
Set stream = fso.CreateTextFile("c:\string.log", True)

'write to file
stream.Write full

'close steam
stream.Close

End Sub

after removing the Scripting Runtime reference?
 
Upvote 0
Rory - Thanks for the response, I have tried with and without the run-time script reference, using your code and get the same error
 
Upvote 0
Then I think your dll requires re-registering.
 
Upvote 0
Does this work?

Code:
Private Sub CommandButton1_Click()
    Dim x As Long, full As String
    full = "xxxx"
    With CreateObject("Scripting.FileSystemObject").CreateTextFile("c:\string.log", True)
        .writeline full
    End With
End Sub

Edit: Early or late bound.. seems maybe your issue is as RoryA suggests.. perhaps a corrupt dll...
 
Last edited:
Upvote 0
apo - Thanks for the response, same error message

All - Any suggestions on replacing corrupt DLL ?
 
Upvote 0
Do you have local administrator rights?
 
Upvote 0

Forum statistics

Threads
1,226,224
Messages
6,189,726
Members
453,566
Latest member
ariestattle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top