LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW and Excel with ActiveX

Hi,
I am using LabVIEW6.1 and I am trying to format data for printout that I have stored in Excel using activeX.

I have three questions that I included the recorded Excel macro for:

1) How do I set the horizontal and vertical page breaks using ActiveX?
Excel macro:
Set ActiveSheet.VPageBreaks(1).Location = Range("F1")
Set ActiveSheet.HPageBreaks(1).Location = Range("A41")
2) How do I set the print area using activeX?
Excel macro:
ActiveSheet.PageSetup.PrintArea = "$A$1:$J$57"
3) How do I left, right center justify the content of cell using ActiveX.
Excel macro:
Range("B3:B8").Select
With Selection
.HorizontalAlignment = xlCenter
End With

Thanks in advance for your time.
KMA
0 Kudos
Message 1 of 4
(4,547 Views)
Your easiest solution is to use an Excel workbook has a template that contains the macro and just execute the macro when the data has been written.

If you prefer to use ActiveX to set the parameters, you can build the functions you need by cascading the methods and properties just like your macro code. The difficulty is always figuring out what is a method and what is a property. Most indexed values need to be specfied with the method node Item. Your functions that you need are:

1) from the worksheet ref wire:
method node Range, wire in Cell1 and Cell2 as strings
wire worksheet ref to property node VPageBreaks
cascade method node Item, wire Index value to 1
cascade property node Location, change to write
wire in the reference from Ra
nge above

2) from the worksheet ref wire:
property node PageSetup
cascade property node PrintArea, change to write
feed in your range as a string value

3) from the worksheet ref wire:
method node Range, wire in Cell1 and Cell2 as strings
cascade property node HorizontalAlignment, change to write
wire in a constant value of -4108

Michael
www.abcdefirm.com
Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.1, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
Message 2 of 4
(4,547 Views)
Thanks for the helpful and very clear answers.

However, I am still having some difficulties with item #1. Adding page breaks. LabVIEW (Excel) generates an error at the location property node. I have attached a copy of the VI.

In addition, from where do I get the HorizontalAlignment constant value of -4108 for center justify. I assume from the Excel help but I cannot find it.

Thanks again.

KMA
0 Kudos
Message 3 of 4
(4,547 Views)
You cannot index the VPageBreaks if you are creating a new worksheet. You would use the index to change an existing VPageBreak. To create a new VPageBreak, replace the Item method with the Add method. Wire the range ref directly into the Before input. I fixed your VI and attached it.

To get the value of the xlCenter constant, open the Visual Basic editor that comes with Excel and use the Object Browser (F2). Type xlcenter into the search window and click the binoculars. The value is displayed at the bottom of the window. You will use that trick a lot when looking for the Excel constants for LabVIEW.

Michael
Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.1, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
0 Kudos
Message 4 of 4
(4,547 Views)