06-07-2011 03:42 AM
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:
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
06-07-2011 03:52 AM
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
06-07-2011 03:53 AM
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.
06-07-2011 03:56 AM
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.
06-07-2011 04:03 AM
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.
06-07-2011 04:12 AM
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
06-07-2011 04:21 AM - edited 06-07-2011 04:24 AM
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
06-07-2011 04:30 AM
Hi!
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.
06-07-2011 08:36 AM
Thanks Even Deejay but I don't succeed in installing it in LabVIEW.
How do you install this toolkit into LabView ?
06-08-2011 01:43 AM
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:
Extract the zipped file here. Then you should get the _Excel folder.
Inside the _Excel folder it should look like this:
You should get the Toolkit as a pallette in your block diagram menu when you rightclick