LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using an Excel macro in LabVIEW

Hi everyone,

 

My macro is in a .XLSM master file in the same folder than the VI.

I would like to use this macro in every .XLS file that LabVIEW will open in another program which is already built.

How to make it on LabVIEW ?? Or how to create a VI where the macro acts directly on the .XLS file open ?

 

This is my macro:

Spoiler

 

 

Sub Incrémental()
Dim Sh As Worksheet
Dim Ch As Chart
Dim i As Integer

Application.ScreenUpdating = False
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Graph").Delete
Application.DisplayAlerts = True
On Error GoTo 0

Set Sh = ThisWorkbook.Worksheets(1)
Set Ch = ThisWorkbook.Charts.Add(After:=ThisWorkbook.Worksheets(1))
With Ch
For i = .SeriesCollection.Count To 1 Step -1
.SeriesCollection(i).Delete
Next i
.Name = "Graph"
.ChartType = xlXYScatterSmoothNoMarkers
.SeriesCollection.NewSeries
With .SeriesCollection(1)
.Name = "T° Sample (°C)"
.XValues = Sh.Range("A:A")
.Values = Sh.Range("B:B")
End With
.SeriesCollection.NewSeries
With .SeriesCollection(2)
.Name = "T° Contact (°C)"
.XValues = Sh.Range("A:A")
.Values = Sh.Range("C:C")
End With
.SeriesCollection.NewSeries
With .SeriesCollection(3)
.Name = "Torque (N.m)"
.XValues = Sh.Range("A:A")
.Values = Sh.Range("I:I")
End With
With .SeriesCollection(1)
.AxisGroup = 2
End With
.HasTitle = True
.ChartTitle.Characters.Text = Sh.Name
With .Axes(xlCategory, xlPrimary)
.HasTitle = True
.AxisTitle.Characters.Text = "Time (s)"
End With
With .Axes(xlValue, xlPrimary)
.HasTitle = True
.AxisTitle.Characters.Text = "Torque (N.m)"
End With
With .Axes(xlValue, xlSecondary)
.HasTitle = True
.AxisTitle.Characters.Text = "Temperature (°C)"
End With
End With
Set Sh = Nothing
Set Ch = Nothing
End Sub

 

 

You can find my VI, jpeg format, attached.
Thanks for your help.
Devour
0 Kudos
Message 1 of 27
(16,577 Views)

Duplicated post: http://forums.ni.com/t5/LabVIEW/macro-LabVIEW-other-file/td-p/1588750

 

There are several examples when searching for 'macros' withing Example Finder.

 

 

 

Christian

0 Kudos
Message 2 of 27
(16,572 Views)

Hi,

 

A good way to make what you want is to use the example in LabVIEW using a macro example.

 

To find it, go to Help--> Search for examples and then Search " macro " and you will get a great example.

0 Kudos
Message 3 of 27
(16,571 Views)

Duplicated post because I didn't find the button to remove it: the name of the post didn't correspond to what I was looking for.

 

I have already seen the exemple about the macro rdastyle, but anyway it didn't help me for what I would like to do.

0 Kudos
Message 4 of 27
(16,568 Views)

Hi,

 

Ok, I understood what you want. In the labVIEW example, the xls contains already the macro. I would try to lauch some .exe via LabVIEW. If it does not work, a very " brutal " solution is to create a macro to clic on the buttons of your .xls to import the macro your created.

Actually,

 

1-You create  you .xls via LabVIEW 

2-You launch the macro via LabVIEW ; this macro will clik for you on the buttons of your .xls to import inside the macro you want to put in your .xls

 

SuperMacro is very quick and easy to use.

0 Kudos
Message 5 of 27
(16,563 Views)

Yes, you understand now !

 

Or maybe is it possible to write the macro inside of the .xls file containing the data ?

The idea of a button in another file is not bad yes, but I will need some help if we take this one.

 

Thanks

0 Kudos
Message 6 of 27
(16,559 Views)

Hi,

 

I really don't know how to insert the code for a macro inside the .xls, during the creation of the .xls.

 

Ok, let me explain a little bit more what I already did with Macro via LabVIEW. Once again, this is a " brutal " solution.

 

I was making some automatic tests on a RFID lector and I was using LV (LabVIEW). 

 

So my protocol was :

1-Launch LV

2-Launch the RFID lector program via LV

3-Launch a macro via LV; This macro was used to clic on the button of the  RFID lector program to configure it.I needed to configure each time the program was launched.

4-Close the RFID lector program via LV

5-Launch the RFID lector program via LV

6-Launch a macro via LV; This macro was used to clic on the button of the  RFID lector program to configure it.I needed to configure each time the program was launched.

7-...

 

To be very clear, this is like you, the user, was in front of your screen, clicking inside your .xls to import your macro !

 

Very brutal but very useful at this time !

2-Launch the RFID lector program via LV

0 Kudos
Message 7 of 27
(16,384 Views)

Hi!

 

Take a look at this.

 

If you go to page two in that thread, I have posted an example on how to copy a template for creating .xls files. I believe you could just put your macro inside a template and then just copy the template. The Free Excel Toolkit also have a vi that you can use to run macros. To use it, just create a macro inside the excel file and give it a name. Then use this name in the vi in Labview. I think you can create a lot of macros and choose whatever macro you wish to run.

Regards,
Even
_________________________________
Certified LabVIEW Associate Developer

Automated Test Developer
Topro AS
Norway
0 Kudos
Message 8 of 27
(16,377 Views)

Thanks Even Deejay but I don't succeed in installing it in LabVIEW.

 

How do you install this toolkit into LabView ?

 

0 Kudos
Message 9 of 27
(16,356 Views)

Hi!

 

I made a zipped file for you. Just extract it in your user.lib folder. On my computer the folder is located here:

C:\Program Files\National Instruments\LabVIEW 2010\user.lib 

 

This is the user.lib folder:

Userlib.png 

Extract the zipped file here. Then you should get the _Excel folder.

Inside the _Excel folder it should look like this:

Inside the _Excel folder.png

You should get the Toolkit as a pallette in your block diagram menu when you rightclick

 

 

Regards,
Even
_________________________________
Certified LabVIEW Associate Developer

Automated Test Developer
Topro AS
Norway
0 Kudos
Message 10 of 27
(16,328 Views)