PC Review


Reply
Thread Tools Rate Thread

application or object defined error on print to file

 
 
cutthroatjess
Guest
Posts: n/a
 
      17th Dec 2007
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
 
Reply With Quote
 
 
 
 
cutthroatjess
Guest
Posts: n/a
 
      17th Dec 2007
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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run Time Error 1004 Application-defined or object-defined error forsimple loop? Need help with what's wrong? Naji Microsoft Excel Programming 2 16th Oct 2009 05:45 PM
Export a chart in a GIF file. Run-time error '1004': Application-defined or object-defined error; cschiffers@gmail.com Microsoft Excel Programming 5 17th Sep 2007 12:48 PM
IE7 and Excel marco "file error: data may have been lost" + "571212 application defined or object defined error" Joshuas Microsoft Excel Discussion 2 27th Nov 2006 09:19 PM
Copying A Range of Cells From one Sheet to Another - Error Application Defined or Object Defined Matt Microsoft Excel Programming 3 25th Jul 2006 01:13 AM
RE: Runtime error 1004- application defined or object defined erro =?Utf-8?B?Tm92aWNl?= Microsoft Excel Programming 0 6th Feb 2006 09:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:04 PM.