I am very new to this. How do you write string and data to a file?
For example, I want to write:
"I am 28 years old"
28 is a calculated number from a function!
I am very new to this. How do you write string and data to a file?
For example, I want to write:
"I am 28 years old"
28 is a calculated number from a function!
Using VBA?
Option Explicit
Sub testme()
Dim FileNum As Long
Dim myYears As Long
myYears = SomeFunction(DateSerial(2000, 12, 31))
FileNum = FreeFile
Close #FileNum
Open "c:\myfile.txt" For Output As #FileNum
Print #FileNum, "I am " & myYears & "years old"
Close #FileNum
End Sub
Function SomeFunction(myDate As Date) As Long
SomeFunction = DateDiff("yyyy", myDate, Date)
End Function
NewGuy100 wrote:
>
> I am very new to this. How do you write string and data to a file?
> For example, I want to write:
> "I am 28 years old"
> 28 is a calculated number from a function!
>
> --
> NewGuy100
> ------------------------------------------------------------------------
> NewGuy100's Profile: http://www.excelforum.com/member.php...o&userid=27935
> View this thread: http://www.excelforum.com/showthread...hreadid=474907
--
Dave Peterson
Perhaps something like this in say, C1:
="I am "&SUM(A1:B1)&" years old"
--
Rgds
Max
xl 97
---
Singapore, GMT+8
xdemechanik
http://savefile.com/projects/236895
--
"NewGuy100" <[email protected]> wrote
in message news:[email protected]...
>
> I am very new to this. How do you write string and data to a file?
> For example, I want to write:
> "I am 28 years old"
> 28 is a calculated number from a function!
>
>
> --
> NewGuy100
> ------------------------------------------------------------------------
> NewGuy100's Profile:
http://www.excelforum.com/member.php...o&userid=27935
> View this thread: http://www.excelforum.com/showthread...hreadid=474907
>
Depends on exactly what you're trying to do.
If the 28 is the return of a function that is in, say cell D1, and you want
the string to be in, say cell D20, then enter this in D20:
="I am "&D1&" years old."
On the other hand, if you would want the cell containing the actual function
to calculate the value *and* return it together with the string, you could
have this in D1:
="I am "&DATEDIF(A3,B3,"y")&" years old."
Where "DATEDIF(A3,B3,"y")" is the formula that returns the value 28.
--
HTH,
RD
==============================================
Please keep all correspondence within the Group, so all may benefit!
==============================================
"NewGuy100" <[email protected]> wrote
in message news:[email protected]...
>
> I am very new to this. How do you write string and data to a file?
> For example, I want to write:
> "I am 28 years old"
> 28 is a calculated number from a function!
>
>
> --
> NewGuy100
> ------------------------------------------------------------------------
> NewGuy100's Profile:
http://www.excelforum.com/member.php...o&userid=27935
> View this thread: http://www.excelforum.com/showthread...hreadid=474907
>
I am sorry about that, I wanted to print it to a text file using vba. I haven't seen it using FileNum before. I've seen it using Write or something similar. Whats the difference between the Write function and thePrint function.
Last edited by NewGuy100; 10-10-2005 at 10:08 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks