Export values in a text file

  • Thread starter Thread starter Matrix
  • Start date Start date
M

Matrix

In the B9 cell I have values that they change dynamically.
Is possible , through VBA, than Excel notices of such variations and
to every change writes those values in a text file with this
structure:

DATE HOUR VALUE
10/30/2003 10:31 5,6
10/30/2003 11:59 5,9
10/31/2003 8:58 6

ETC.

Can you help me?

Thanks
 
Assume this change is caused by some DDE connection

Look at SetLinkOnData property of the Workbook object to designate a macro
to run when there is a change.

Then have this macro write the data.

In xl2000 and later, I believe you can use the change event for this.

http://www.cpearson.com/excel/event.htm for a description of events.
 
You can get sample code here:
http://support.microsoft.com/support/excel/content/fileio/fileio.asp
File Access with Visual Basic® for Applications


Thanks for support.
I've written this code, but it doesn't work.
Can you tell me why?


Sub Worksheet_Change(ByVal Target As Range)


If Target.Value = Foglio2.Range("D9").Value Then MyTxtFile

End Sub


Sub MyTxtFile()
Const Percorso = "c:\txtExport.txt"

Open Percorso For Append As #1
Print #1, Date, Time, Cells(9, 4).Value
Close #1

End Sub
 
Hi,
Target.Value would be the contents of D9.
For the event to evaluate to true and run Mytexfile you have to give it the
cell address so it knows which cell is the current cell.
This way you can evaluate more than one cell.

Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$D$9" Then mytxtfile

End Sub

Sub MyTxtFile()
Const Percorso = "c:\txtExport.txt"

Open Percorso For Append As #1
Print #1, Date, Time, Cells(9, 4).Value
Close #1

End Sub
 
Hi,
Target.Value would be the contents of D9.
For the event to evaluate to true and run Mytexfile you have to give it the
cell address so it knows which cell is the current cell.
This way you can evaluate more than one cell.


Ok, now it works, but there is a big problem
Change Event doesn't work with DDE link:
http://support.microsoft.com/?kbid=172832

The right solution is SetLinkOnData, but i haven't understood how it
works.

Please Jaf can you tell me how i can adapt previous vba code with
SetLinkOnData?

Thanks a lot
 
Why not read the sample code given in the link you show. It shows you how
it works. Each link has to be set separately and a macro assigned. Since
you only have one cell, D9, that would only need one macro assignment - the
macro would be Mytxtfile. I found you need to do to a calculate in the in
the macro to get the updated value.

Recall I told you about SetLinkOnData in my first post and the fact that
Change only works in xl2000 and later, just like in the article.
 
Back
Top