View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
deltaquattro deltaquattro is offline
external usenet poster
 
Posts: 65
Default Cannot write the contents of an Object to file

Hi Peter,

thanks for your answer and your suggestions. However, I still have the
same error.
I found out that when test() and WriteDataToFile() are located in the
same Module1 inside the same workbook (for example Test.xls), and
CRecord is in the same workbook, then no problem occurs.
However, in my setup, is inside MyLibrary.xla, a collection of all
modules which I reuse in different projects, while Module1 (test())
and CRecord are inside Test.xls. MyLibrary.xla is added to the
References of Test.xls. In this case, I get the error:

"Run-time error 52:
Bad file name or number"

Should I give up on the idea of adding my more or less general data
writing function in to MyLibrary.xla? Or is there a way to get things
working? Thanks again,

Best Regards,

deltaquattro



On 26 Apr, 13:21, "Peter T" <peter_t@discussions wrote:
Works fine for me although I did have to change
For I = 1 To NLines
to
For I = 1 To Ubound(pLinea)

I can see all sorts of problems ahead unless you are very careful, eg what
happens if/when
If IsObject(Element) Then
but Element doesn't have a method .PrintToFile

At the very least I'd suggest

on error goto errExit
*FNumber = FreeFile

'code

done:
on error resume next
Close #FNumber

exit function
errExit:
resume done
end function

Another thought, "foo.txt"? The code would fail if the curDir doesn't have
access to write files (often a problem Vista / W7), why not qualify it, eg
application.defaultfilepath & "\foo.txt"

Regards,
Peter T