ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Bad File name or number (https://www.excelbanter.com/excel-programming/419737-bad-file-name-number.html)

thorn2fish

Bad File name or number
 
I had a small subroutine where I read one text file and wrote to another. It
worked fine, but then I wanted to break the write (Print statement) out
various subroutines. Now I am receiving error:
Run-Time error '52':
Bad File name or number

Any thoughts on how to acomplish this? I want to open the input and output
files in the main sub, and then read/write in various sub-routines.


mudraker[_406_]

Bad File name or number
 

without seeing your code it's hard to give a specific answer

If you use commands like this
Print #1, "This is a test" ' Print text to file.

you probally need a glabal variable to hold your free file number and
then use that variable within each sub routine

use this to get a free file numer
dim iFF as integer
iFF = FreeFile

then use variable in command
Print #myVariable, "This is a test" ' Print text to file.
*-Post posted before response, posts merged!*-
Oops typo in my previos reply
Print #myVariable, "This is a test" ' Print text to file.

should be
Print #iFF, "This is a test" ' Print text to file.


--
mudraker

If my reply has assisted or failed to assist you I welcome your
Feedback.

www.thecodecage.com
------------------------------------------------------------------------
mudraker's Profile: http://www.thecodecage.com/forumz/member.php?userid=18
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=27096


thorn2fish

Bad File name or number
 
You would think I would know better. I sat here trying to execute just the
subroutine instead of the main sub. It is working correctly.

Thanks for the qucik response though!


All times are GMT +1. The time now is 12:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com