LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help in DDE communications with Excel

Hello.

My name is Miguel Cabrita and I'm from Portugal, Europe. I am developing a
program with LabVIEW that uses the FiedPoint I/O modules from National
Instruments to verify the connections of electrical components that are
about to be mounted in the trains for the Lisbon Subway. Since the system
is to be used by several workers in the factory it is necessary to register
each individual use. LabVIEW offers the chance to communicate easily with
MS Excel using the DDE protocol. The examples provided with the LabVIEW
CD-ROM show how to open a file and how to write to specified cells. But I
have three problems for which I can't find any clue:

1. How can I write to the row immediately after the last one used ? Is
ther
e a way to "call" the function COUNT that exists in Excel ? The program
is supposed to be used for a lot of days but started only once a day, we
don't want it to run forever . One option would be to write the number of
rows used in a file and read it each time we initialize the program, but
this doesn't seem a good idea since it writes "unknown" files to disk.

2. When I want to write to the first cell of the first row the channel
value to the poke vi is R1C1. The problem is that row in Portuguese is
"linha" and I must put L1C1 if I'm using the Portuguese version of Excel.
Is there a way to pass the channel value in an universal way, so that the
version of Excel (English or Portuguese) doesn't matter ?

3. And, last but not least, is it possible to close Excel and its sheets
and save the changes directly from LabVIEW using the DDE protocol ?

Thank you for your attention and sorry to take your time with such a long
mail. Any help would be greatly appreciated, be it an answer to my
ques
tions or a http address to consult.

Luis Miguel Cabrita � Portugal
Email: jcabrita@mail.eunet.pt
Home Page: http://home.eunet.pt/jcabrita/
0 Kudos
Message 1 of 5
(4,360 Views)
.... LabVIEW offers the chance to communicate easily with
> MS Excel using the DDE protocol. The examples provided with the LabVIEW
> CD-ROM show how to open a file and how to write to specified cells. But I
> have three problems for which I can't find any clue:
>
> 1. How can I write to the row immediately after the last one used ? Is
> there a way to "call" the function COUNT that exists in Excel ? The program
> is supposed to be used for a lot of days but started only once a day, we
> don't want it to run forever . One option would be to write the number of
> rows used in a file and read it each time we initialize the program, but
> this doesn't seem a good idea since it writes "unknown" files to disk.
>
> 2. When I want to write to the first cell of the first row the channel
> value to the poke vi is R1C1. The problem is that row in Portuguese is
> "linha" and I must put L1C1 if I'm using the Portuguese version of Excel.
> Is there a way to pass the channel value in an universal way, so that the
> version of Excel (English or Portuguese) doesn't matter ?
>
> 3. And, last but not least, is it possible to close Excel and its sheets
> and save the changes directly from LabVIEW using the DDE protocol ?
>

It may be possible to do each of these items with DDE and Excel, but I don't
know how, and most other people won't know how, and MS never documented this
very well. They have moved their inter-application control from DDE to ActiveX
Automation. It is documented, it is faster, and it is more predictable.

In your case, I get the feeling that you simply need to write to a spreadsheet
file. If this is the case, the easiest way is to produce a
tab-delimited file
using the builtin LV icons or formatting your own and writing the text file.

Excel will load these files, as will almost any other spreadsheet
program, and
assuming you don't need fancy items like sheets, it is much simpler and faster
than trying to control Excel to do your file I/O. If you do need the
files to
be in Excel binary format for some reason, you can have Excel load and
save the
file using ActiveX.

Greg McKaskle
0 Kudos
Message 2 of 5
(4,359 Views)
In article <3736CFC7.A6DFAC8A@austin.rr.com>,
GMCKASKLE@austin.rr.com wrote:
> ... LabVIEW offers the chance to communicate easily with
> > MS Excel using the DDE protocol. The examples provided with the
LabVIEW
> > CD-ROM show how to open a file and how to write to specified cells.
But I
> > have three problems for which I can't find any clue:
> >
> > 1. How can I write to the row immediately after the last one
used ? Is
> > there a way to "call" the function COUNT that exists in Excel ? The
program
> > is supposed to be used for a lot of days but started only once a
day, we
> > don't want it to run forever . One option would be to write the
number of
> > rows used in a file and read it each time we initialize the
program, but
> > this doesn't seem a good idea since it writes "unknown" files to
disk.
> >
> > 2. When I want to write to the first cell of the first row the
channel
> > value to the poke vi is R1C1. The problem is that row in Portuguese
is
> > "linha" and I must put L1C1 if I'm using the Portuguese version of
Excel.
> > Is there a way to pass the channel value in an universal way, so
that the
> > version of Excel (English or Portuguese) doesn't matter ?
> >
> > 3. And, last but not least, is it possible to close Excel and
its sheets
> > and save the changes directly from LabVIEW using the DDE protocol ?
> >
>
> It may be possible to do each of these items with DDE and Excel, but
I don't
> know how, and most other people won't know how, and MS never
documented this
> very well. They have moved their inter-application control from DDE
to ActiveX
> Automation. It is documented, it is faster, and it is more
predictable.
>
> In your case, I get the feeling that you simply need to write to a
spreadsheet
> file. If this is the case, the easiest way is to produce a
> tab-delimited file
> using the builtin LV icons or formatting your own and writing the
text file.
>
> Excel will load these files, as will almost any other spreadsheet
> program, and
> assuming you don't need fancy items like sheets, it is much simpler
and faster
> than trying to control Excel to do your file I/O. If you do need the
> files to
> be in Excel binary format for some reason, you can have Excel load and
> save the
> file using ActiveX.
>
> Greg McKaskle
>
Why not save your data to a buffer sheet and use macro's to move the
data wherever you want. Once perfected you can then use DDE to repeat
those moacro's.
The DDE commands are identical to macro commands. (The old pre-visual
basic macro commands certainly do work). You can certainly use DDE
commands to close sheets but I have never tried using them to close
excel, it should work you can open it using DDE.

Rob Barker


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
0 Kudos
Message 3 of 5
(4,359 Views)
"Lu�s Miguel Cabrita" wrote:

> Hello.
>
> My name is Miguel Cabrita and I'm from Portugal, Europe. I am developing a
> program with LabVIEW that uses the FiedPoint I/O modules from National
> Instruments to verify the connections of electrical components that are
> about to be mounted in the trains for the Lisbon Subway. Since the system
> is to be used by several workers in the factory it is necessary to register
> each individual use. LabVIEW offers the chance to communicate easily with
> MS Excel using the DDE protocol. The examples provided with the LabVIEW
> CD-ROM show how to open a file and how to write to specified cells. But I
> have three problems for which I can't find any clue:
>
> 1. How can I write to the row immediately after the last one used ? Is
> there a way to "call" the function COUNT that exists in Excel ? The program
> is supposed to be used for a lot of days but started only once a day, we
> don't want it to run forever . One option would be to write the number of
> rows used in a file and read it each time we initialize the program, but
> this doesn't seem a good idea since it writes "unknown" files to disk.
>
> 2. When I want to write to the first cell of the first row the channel
> value to the poke vi is R1C1. The problem is that row in Portuguese is
> "linha" and I must put L1C1 if I'm using the Portuguese version of Excel.
> Is there a way to pass the channel value in an universal way, so that the
> version of Excel (English or Portuguese) doesn't matter ?
>
> 3. And, last but not least, is it possible to close Excel and its sheets
> and save the changes directly from LabVIEW using the DDE protocol ?
>
> Thank you for your attention and sorry to take your time with such a long
> mail. Any help would be greatly appreciated, be it an answer to my
> questions or a http address to consult.
>
> Luis Miguel Cabrita - Portugal
> Email: jcabrita@mail.eunet.pt
> Home Page: http://home.eunet.pt/jcabrita/

Have you tried the Active X controls instead of DDE?
Some of the features that you need are already controlled by Active X.
You can see examples of how to use Active X and Excel in the National
Instruments Developers Zone web page (below)

http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&466756C38892E076862568930072D934&cat=9C6DF90777E5A78206256874000FA14E#2

I hope this can help.

Horacio Castilleja
abuelazo@hotmail.com
0 Kudos
Message 4 of 5
(4,359 Views)
Heve you consider using the LabVIEW MS Office Toolkit? It's about ~$600 bucks but it's worth it if you just need simple reporting of your data.

Otman Estrada
Raytheon Company
0 Kudos
Message 5 of 5
(4,358 Views)