ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Export values in a text file (https://www.excelbanter.com/excel-programming/281164-export-values-text-file.html)

Matrix[_2_]

Export values in a text file
 
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
structu

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

Tom Ogilvy

Export values in a text file
 
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.

--
Regards,
Tom Ogilvy
"Matrix" wrote in message
...
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
structu

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




Matrix[_2_]

Export values in a text file
 
On Fri, 31 Oct 2003 14:51:18 -0500, "Tom Ogilvy"
wrote:


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.


If it isn't very difficult, can you give me an exemple of vba code?
I'm a novice

Thanks

Tom Ogilvy

Export values in a text file
 
You can get sample code he
http://support.microsoft.com/support...eio/fileio.asp
File Access with Visual Basic® for Applications


--
Regards,
Tom Ogilvy

Matrix wrote in message
...
On Fri, 31 Oct 2003 14:51:18 -0500, "Tom Ogilvy"
wrote:


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.


If it isn't very difficult, can you give me an exemple of vba code?
I'm a novice

Thanks




Matrix[_2_]

Export values in a text file
 
On Sat, 1 Nov 2003 11:48:27 -0500, "Tom Ogilvy"
wrote:

You can get sample code he
http://support.microsoft.com/support...eio/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



jaf

Export values in a text file
 
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

--

John

johnf202 at hotmail dot com


"Matrix" wrote in message
...
On Sat, 1 Nov 2003 11:48:27 -0500, "Tom Ogilvy"
wrote:

You can get sample code he
http://support.microsoft.com/support...eio/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





Matrix[_2_]

Export values in a text file
 
On Sun, 2 Nov 2003 08:27:45 -0500, "jaf" wrote:

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

Tom Ogilvy

Export values in a text file
 
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.

--
Regards,
Tom Ogilvy

Matrix wrote in message
...
On Sun, 2 Nov 2003 08:27:45 -0500, "jaf" wrote:

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





All times are GMT +1. The time now is 10:42 PM.

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