View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
cutthroatjess cutthroatjess is offline
external usenet poster
 
Posts: 3
Default application or object defined error on print to file

Sorry, I found my error. On using a different sheet, the number of field
values changed. On:
For l = Cells(2, 17) To Cells(2, 18), 17 should have been 16 and 18 should
have been 17.

Thanks anyway!

Jesse

"cutthroatjess" wrote:

In another sub, this works just fine! The only difference is that I have it
select a different sheet and do the same thing.

This is failing on : Print #3, Trim(Cells(l, 1)) 'sample id
saying that there is an application-defined or object-defined error.
Sometimes it says the file is already open.

OK Here's my code:

Public Sub cations()
Dim l, m, n As Integer

Sheets("cations").Select


Open "c:\textfiles\postmcrocations.txt" For Output As #3
Open "c:\textfiles\temp\postmcrocations.tmp" For Output As #4



For l = Cells(2, 17) To Cells(2, 18)
'header info
Print #3, Trim(Cells(l, 1)) 'sample id
Print #4, Trim(Cells(l, 1))

Print #1, "$cations" 'multicomponent
Print #1, "6" 'number of analytes
For m = 2 To 7
n = m + 7
Print #1, Trim(Cells(1, m)) 'analyte name
Print #1, Trim(Cells(l, m)) 'analyte value
Print #1, Trim(Cells(l, n)) 'chromatagram location for
secondary result)
Next m


Next l

Close #3
Close #4

End Sub


Thanks!

Jesse