What is FreeFile() function???

  • Thread starter Thread starter Robert Crandal
  • Start date Start date
R

Robert Crandal

I'm trying to understand what exactly is the purpose of the
VBA FreeFile() function??? If I call this function inside
one of my VBA modules, it will return a numerical value.
What is this numerical value??

thank you
 
Robert Crandal said:
I'm trying to understand what exactly is the purpose of the
VBA FreeFile() function??? If I call this function inside
one of my VBA modules, it will return a numerical value.
What is this numerical value??

thank you

Robert,

Here are two ways of accessing rather immediate assistance

1. VBA Help
Search "freefile". It lays it out in plain english.

2. Google. Here's one of many hits.
http://zo-d.com/blog/archives/programming/vba-writing-to-a-text-file-ms-project-excel.html
In the first paragraph at this site, it states "Use FreeFile to get the
file number of the next file."

Pretty straightforward.

Skiffle
 
Robert,

In VB you can open files and then manipulate them using FileNum.

Now in a simple piece of code you could use Filenum 1 (one) manually
assigned in the fairly certain knowledge the number isn't being used but in
more complicated code this become very risky indeed because if you manually
assign the number you may start geting uppredictable results.

Hence FreeFile() which allocates the next 'unused' number. In the snippet
below Filenum is assigned to the next free number by FreeFile and thereafter
the file is referred to by the number assigned to it and not the name


Dim FileNum As Integer
LogMessage ="Some very important text"
FileNum = FreeFile
Open FName For Append As #FileNum
Print #FileNum, LogMessage
Close #FileNum ' close the file
End Sub


--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
Back
Top