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

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, ABCDEF
Certified LabVIEW Developer, MCP
Find and fix bad VI Properties with Property Inspector
Attachments:
Excel_Page_Break_mod.vi ‏67 KB

Similar Messages

  • How to create rtf template to view report in Word and Excel, with numeric f

    Hi,
    Please help me!
    How to create rtf template to view report in Word and Excel, with numeric formatted fields (like this 999 999 999,99 with spaces between numbers) and then end user be able to process those fields with Excel tools (sum, etc).
    Thank you.

    From what I have seen Excel can not handle 999 999 999.00. You can use 999999999.00 and then format it as you want in the xls bt you can not have values like 999 999 999.00 coming from publisher output and have functions on the values in Excel
    Tim

  • Can't open excel file after saving and closing excel with activex

    I'm using activex to write and save excel files in LabVIEW. My application opens excel (not visible)writes a file, saves it, and then closes both the file and excel. When I try to open the file Excel opens but the file is not displayed, I see the excel header and footer but the file itself does not display. My application is still running at this point. Any suggestions?

    It is critical when using ActiveX with Excel that ALL refnums be properly closed when they are no longer used. Just a single refnum left open will cause the exact situation that you describe. Typically, but not required, the refnums will be closed in the reverse order in which they were created. Here is a good sequence:
    Open Application ref
    Property Workbooks ref
    Open Workbook ref
    Close Workbooks ref
    Select Sheet ref
    Select Range ref
    Write Value2 to Range
    Close Range ref
    Close Sheet ref
    Save Workbook
    Close Workbook ref
    Close Application ref
    When you have properly closed all refnums, the problem will disappear.
    Michael Munroe
    Certified LabVIEW Developer
    www.abcdef.biz
    Michael Munroe, ABCDEF
    Certified LabVIEW Developer, MCP
    Find and fix bad VI Properties with Property Inspector

  • How can i work simultaniously with labVIEW and Excel ?

    Hello . I study engineering and need some help with labVIEW, and the connection to microsoft excel.

    Hi
    NI offers an "Report generation toolkit". You get some VI's with this toolkit and so you can directly create your reports from LV.
    Another possibility is the communication through ActiveX. There is a nice link with application notes and LV examples for that:
    http://zone.ni.com/devzone/devzone.nsf/webcategories/C3E56C69D399361E86256AB7006A9149?opendocument&node=DZ53003_US
    Regards,
    Luca

  • Closing Excel with ActiveX causes problem

    Hallo,
    I am having a problem using ActiveX and Excel. I
    am using NT 4.0, Service Pack 3, Excel 97, Service
    Release SR1 and LabVIEW 5.1.
    My LV application opens an Excel worksheet,
    operates on the sheet and then closes it by using
    ActiveX. Everything works fine until I try to
    start Excel from the desktop after running my LV
    application. Then I get an "Exception access
    violation" generated by excel.exe. It seems like
    my application does not manage to end the
    excel.exe process which leads to the "violation
    error" next time Excel is to be opened. To quit
    Excel I call the "quit" method in
    Excel_Application and then call the "Automation
    Close".
    Anyone knows how to solve this?
    \Helena Dimitriou
    Sent via Deja.com
    http://www.deja.com/
    Share what you know. Learn what you don't.

    Greg, this is the problem: Granted that Excel closes properly when users try to close all opened refnums, when this VI is used as subvi (loop) "Excel.exe" does not close (every instance opened). It stays in the Task Manager until the program that uses this subVI ends. This is not good because "Excel.exe" uses a large memory.Just think what will happen if I try to use this "Excel" subVI a couple of hundred times in an application VI. It leaves at least 6000kb of memory for every instance multiply it by a couple of hundreds, then your PC crashes.
    Another, open only one instance, the "Excel.exe" process remain in the Task Manager.
    What can you say? You haven't tried?
    Try this: create a vi which will open the Excel Application (wire the "open new instance
    " terminal to TRUE), open an existing Excel workbook, add sheet, write numbers 1 to 255 from A1 to A255 and B1 to B255 to the added and close the ranges where the numbers are written, close the added sheet, close the opened workbook and close the Excel application. Then use this vi in a loop that iterates 500 times so that 500 sheets (plus three as default to Excel) will be added to the opened workbook. Before running the VI with the loop, open your Task Manager>>Processes. Run the VI and monitor how many "Excel.exe" while the loop is running and the memory usage it consumes. And take note of the "Excel.exe" which will remain in the Task Manager after the vi with loops ends. Then e-mail me ([email protected] OR [email protected]) of things that went wrong and how to solve the problems that causes for things to go wrong.
    Of course you can also send your VI.
    This my main problem.

  • Writing array to Excel with ActiveX

    Common question I suppose, but I'm still having issues despite reading several posts about the issue.
    Problem is I'm trying to write a 1D array of data to 1 column in an excel document. However, unless I add an artificial column (of blank values or some other bogus #), ActiveX only writes the 1st value of my array to the column.
    Look at the attached. In Picture 1 I add an articial column and everything writes fine. In Picture 2 I don't add this column and only the 1st value of the array gets written in each row.
    Suggestions?
    Thank you.
    Solved!
    Go to Solution.
    Attachments:
    images.jpg ‏233 KB

    I haven't done much with Excel and LabVIEW by way of ActiveX.  Creating a small VI and duplicating what you show in your screenshot, I see the same behavior.
    I believe that Excel interprets a 1-D array as something that runs horizontally.  So a 1-D array consists of a single row of cells and N number of columns.
    (Actually LabVIEW interprets a 1-D array like this as well, but it allows you to show an array onscreen either vertically or horizontally.)
    Converting to a 2-D array and transposing is what you need to do to have that 1-D array be treated as a single column of cells.
    Note that you don't have to use build array and append an empty array to it.  You can just use build array as is and it will turn a 1-D array into a 2-D array.
    Attachments:
    Example_VI.png ‏22 KB

  • LabView and Excel

    I want to store simple characters (measurement data) to a .txt file. These
    data are used for spreadsheet (e.g. Excel) test protocols. What I am
    looking for is the possibility to launch a test protocol print out from
    LabView with the stored data.
    How can I launch easlily the print out with the stored data?
    Thanks
    Mike

    This is very easy with ActiveX. Just create an Excel template file with the raw data on Sheet1 and your report on Sheet2. If you need complex analysis of the data, include that on a separate sheet. I have used Excel as a report generator for several projects.
    Using ActiveX you need to:
    1. Open Excel
    2. Open the data file (Workbooks.OpenText)
    3. Copy the data (Sheets(1).CurrentRegion.Copy)
    4. Open the template file (Workbooks.Open)
    5. Paste the data (Application.Paste "Sheet1!A1")
    6. Send Sheet2 to the printer (Worksheet.PrintOut)
    7. Optionally Save As... to a new xls file
    8. Close both Workbooks (Workbook.Close SaveChanges=False)
    Michael Munroe, ABCDEF
    Certified LabVIEW Developer, MCP
    Find and fix bad VI Properties with Property Inspector

  • Connecting LabView and Excel live

    Hi,
    I am wondering how to get the data I am collecting with LabView into Excel live.  I would appreciate any help anyone could give.  Thanks in advance. 

    There is an example that ships with LabVIEW that shows you how to use ActiveX to write to an Excel workbook.
    Alternate solutions:
    Use the Reporting Toolkit
    Use the Write to Spreadhseet File VI which writes a text file, but it can be opened with Excel. 

  • Help with quitting Excel with activex (save-dialog)

    Hello.
    I have following question.
    I have a VI that writes data from measurement devices into an excel file. Afterwards I want to change the order of the entries with the help of activex.
    All that works fine, but when I quit excel the save-dialolg always pops up. I searched this board for possible solutions and experimented quite a bit but I still get one dialog at the end.
    Well, now at least it is only one and not multiple ones. The loop in my the implementation for the data manipulation might be the cause, but if it is it, i don't know why or how to solve it. But maybe it is something different. Anyway, I cannot find the reason.
    Some help would be really appreciated .
    Thank you very much in advance.
    Regards
    CD
    Solved!
    Go to Solution.
    Attachments:
    labview excel.JPG ‏136 KB

    OK. In the attachment is a picture of the modifications.
    Now I have to two problems.
    First, after running it in highlight modus, I now know the dialog pops up at the _Workbook.close invoke node. Despite setting true to SaveChanges.
    Second, I now get an error code -2147352565 - unknown error at invalid index. and nothing gets saved.
    Attachments:
    labview excel changesI.JPG ‏79 KB

  • Handling Popups in Excel with ActiveX

    I'm having a problem similar to the problem referenced in this post:
    https://forums.ni.com/t5/LabVIEW/Handling-popups-of-Excel-while-editing-it-via-Active-X-Control/td-p...
    The difference being...
    My company has an Excel "database" that stores all of our product information. When starting my application I read from this database using ActiveX. Recently this Excel sheet was updated to include new capabilities by someone else within my company.
    Now, when opening this particular worksheet, I get this message:
    It doesn't come to the front of the screen, and unless the user realizes that it is coming the LabVIEW program seems to hangup, causing the user to close the LabVIEW program, because they don't realize that LabVIEW is waiting on Excel, which is waiting on the user to make a selection on this popup.
    In the post I referenced above, they get around this by using a Property Node with the "Display Alerts"  property set to false. This works for hiding errors but doesn't seem to work for this instance. 
    Is there a way, through ActiveX, to "click" the "Don't Update" button without the user having to do this.
    OR
    Worst case scenario, is there a way to bring this popup to the front to alert the user that Excel needs input?
    Thanks
    Solved!
    Go to Solution.

    If anyone stumbles upon this page looking for a solution, here is how I ended up solving the issue:
    http://support.microsoft.com/KB/826921

  • Logitech Game Controller for use in Labview and dealing with possible disconnects

    Hello all, I would like to see if there are any suggestions on the following issue. In effect I am using a Logitech game controller to manipulate large scale robots. During operation with these robots I need to plan for the inevitable "accidental" disconnection of the game controller from the computer running labview while it is under operation. Simple to say I can throw the system into standby upon the "ERROR" messages I get, but I want to programmatically be able to "reset" the controller (ie wait for it to be plugged back in) and have the program continue working. However with my work and research thus far that isn't the case. I end up with the same error (even when reconnected, attempted re-initialize, closing the connection, with time delays, and re-initailizing after closing all connections). Nothing seems to work other than closing the program and restarting it (which for the consumer this would be quite frustrating). Suggestions?
    Also on a similar note if anyone has any ideas on how to scan for devices prior to using them would be helpful too.
    I currently am running Labview 2009 in windows 7. I do realize windows has its unique way of dealing with plug and play devices, and suspect that I may have to play with these features, but I don't know this topic very well.
    Thank you all in advance!

    Hey Dashiva,
    I am assuming that the Game Controller that you are using is connected via USB. Does it show up in the computer's Windows menu when it is plugged in? If so, you can make calls to it using .NET controls that could access the device once it is re-connected. I would also try simply hitting F1 and see if that allows the program to reset the controller.
    Good Luck,
    Doug B
    National Instruments
    Applications Engineer
    Applications Engineer
    National Instruments

  • Excel and Macro with Labview

    Hello every body,
    I have to read to excels files int order to treat them and generate graphs ( 3 graphes) in another excel file. to do that, i want to use the Macro for Excel.
    How can i do, I want to write my basics codes VBA even in Labview.
    Tks for your help

    It also requires the Office Report Generation Toolkit.....
    So maybe i shorten this and tell you that the toolkit includes a VI called "Excel Run Macro.vi". Within this VI, an ActiveX call is done to the Excel Application class called "Run" taking many optional arguments.
    So working with ActiveX to interface with Excel will give you the needed toolsuite.
    Please refer to msdn.microsoft.com for specific help on Microsoft products (like Excel). You can use this link for an easier start.
    hope this helps,
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Excel Get ActiveX References​.vi and closing references -- grrr

    I'm new to ActiveX stuff, but eager to learn! 
    The "grrr" in my Subject line is a reference to how I feel about LabVIEW's documentation from time to time.  I'm a dinosaur who came from text-based programming, and did a fair amount of C coding, so sometimes with LabVIEW I'm left with this awful feeling in the pit of my stomach like, "Good grief!  How much memory must LabVIEW be hogging up in the background when I use this vi?" or "What happens to those variables (wires) in that subVI when it completes but doesn't close?  What are their statuses when I come back in the next time?" or "What if I put a lot of elements into that array the first time and then started from element zero the second time and just put in a few?  What has happened with the memroy that was allocated when there were a lot of elements?"
    Today I'm stewing about this "Excel Get ActiveX References.vi," and what happens to the "ActiveX references" it generates each time I call the subVI in which "Excel Get ActiveX References.vi" lives.  I think that at least one of the "ActiveX references" it generates when I call it is of the type Excel._Application.  Then there appears to be an Excel._Workbook, and others.  You see, I've used "Excel Easy Report.vi" to put some data into an Excel spreadsheet, and I want to tell Excel to do a "Save" on the open spreadsheet.  I think ActiveX is the (a) right way to do that, so I'm wading into the ActiveX fray...  But this "Excel Get ActiveX References.vi" says in its help file, "Do not close ActiveX references opened with the Excel Get ActiveX References VI. References must remain open until the report is closed. Otherwise the error 3001 will occur."  Well, these Excel workbooks that get created by my VI could well stay open until after my LabVIEW VI terminates!
    So (finally), here are some of my quesitons:
    1)  When I go through my subVI once, pointing to one workbook, I'll get one set of references "created" or "opened" or whatever you call it when ActiveX references spring into existance.  Now, when I exit the subVI, is it going to automatically try to "close" those ActiveX references?  I don't suppose so, since subVI's stay in memory until the calling VI closes.
    2)  Now, I come back into my subVI a second time.  New workbook gets created, so I get new references.  Ok, fine.  Uh oh!  What happened to those old references?  I suppose that if I didn't somehow save them off, I've probably lost the ability to get them back (maybe I'm wrong, but I don't need them back), but is LabVIEW going to "close" those old references (from previous times through the subVI) because I can't get to them anymore?  Won't that cause the dreaded error 3001?  If LabVIEW is not going to "close" them, what in tarnation happens to them (the old C programmer in me creeping back out)??  Now it's some oddball, orphaned reference, floating out there, hogging memory, waiting to make something crash intermittently and be a debugging nightmare?
    3)  Now, here's the real scary one.  I think I might dodge the "error 3001" bullet in questions 1) and 2), but now let's say the user closes my LabVIEW application while Excel is still open.  All those workbooks are still open.  Presumably, all those ActiveX references I was not supposed to close are still open.  I really hope that LabVIEW is decent enough to close/erase/delete/blow-away (whatever the right word is) all those ActiveX references which were opened/created by "Excel Get ActiveX References.vi" when my program terminates.  But, oh no!  Won't the error 3001 come along then?  I suppose I can just dump it in the shutdown error handling.
    Well, thanks for reading my novel.  I don't know what can be done with LabVIEW documentation to make it more satisfying to folks like me, but perhaps someone can weigh in on all my ActiveX questions here.
    Thank you in advance,
    Steve Brady
    Solved!
    Go to Solution.

    You need to close EVERY ActiveX reference you open.  If you don't you'll end up with some Excel processes running even after LabVIEW exits.  You can see them in Task Manager.
    I, personally, don't like the LabVIEW Report Generation Tool Kit for working with Excel.  I don't think it's flexible enough.  I have a growing library of VIs that I've written that open, manipulate, and close Excel.  Some references I pass from VI to VI and some I close right after I use them.  It all depends on what I'm doing.  If I want to enter read or write data from/to a certain range I'll get the range reference, read or write the data, then close it right away because I have no use for it any more.  On the other hand, when I open Excel or a Workbook I keep the reference until I'm done, which could be later in the program.
    1)  When I go through my subVI once, pointing to one workbook, I'll get one set of references "created" or "opened" or whatever you call it when ActiveX references spring into existence.  Now, when I exit the subVI, is it going to automatically try to "close" those ActiveX references?  I don't suppose so, since subVI's stay in memory until the calling VI closes.
    2)  Now, I come back into my subVI a second time.  New workbook gets created, so I get new references.  Ok, fine.  Uh oh!  What happened to those old references?  I suppose that if I didn't somehow save them off, I've probably lost the ability to get them back (maybe I'm wrong, but I don't need them back), but is LabVIEW going to "close" those old references (from previous times through the subVI) because I can't get to them anymore?  Won't that cause the dreaded error 3001?  If LabVIEW is not going to "close" them, what in tarnation happens to them (the old C programmer in me creeping back out)??  Now it's some oddball, orphaned reference, floating out there, hogging memory, waiting to make something crash intermittently and be a debugging nightmare?
    3)  Now, here's the real scary one.  I think I might dodge the "error 3001" bullet in questions 1) and 2), but now let's say the user closes my LabVIEW application while Excel is still open.  All those workbooks are still open.  Presumably, all those ActiveX references I was not supposed to close are still open.  I really hope that LabVIEW is decent enough to close/erase/delete/blow-away (whatever the right word is) all those ActiveX references which were opened/created by "Excel Get ActiveX References.vi" when my program terminates.  But, oh no!  Won't the error 3001 come along then?  I suppose I can just dump it in the shutdown error handling.
    1)  No, LabVIEW will NOT close those references.  You need to make sure that happens.
    2)  You can save the references in a functional global or use a class but if you're not going to save them close them as soon as you're done with them.
    3)  Your user should not be able to close your LabVIEW application without it going through the shutdown routine you've created for your program.  The ABORT button should never be exposed to the user and you should capture and discard the panel close event so your program ALWAYS shuts down is an orderly fashion.  If you don't you will have fragments of Excel hanging around in your operating system and will have to kill those processes using Task Manager.  That should only be a problem during development, not once deployed.
    I used to program in C and Assembly many moons ago.  You should have seen my first LabVIEW code.  I go back and look at it just so I can see how far I've come in the last 12 years.  I feel your pain.
    Kelly Bersch
    Certified LabVIEW Developer
    Kudos are always welcome

  • How to list all currently open Excel files with ActiveX?

    Hello all!
    I would like to program with ActiveX a way to retrieve a list (array of strings) of the filenames of the currently opened Excel files in windows. However, I am fairly new to the ActiveX/Excel business in LV and after hours looking at the "millions" of objects in the property nodes I give up and hope some kind soul here can help me. I couldn't find any information in this forum regarding the same issue, although some were close
    I am using LV 7.1 without the Report Generation Toolkit.
    Thanks!
    /Goran

    Hi KC,
    thanks for your reply. I have in fact been able to find the desired things in the ActiveX properties/methods for Excel in LabView. It took me some looong work going through the functions which I suspected to be the ones. Anyway, I post a little jpeg here of the code if someone ever needs the same functionality. What it does is that it checks how many Excel workbooks are open and controls if each of them matches the searched Excel filename, if one does, it is closed.
    Enjoy
    /Goran
    Attachments:
    List open excel sheets and close open ones.jpg ‏104 KB

  • Read 2 Strings from EXCEL with GOOP or ActiveX?

    Hello,
    i use Labview 5.1 with WIN NT4.0 SP6a and i programm a fuzzy Logic tool for a exam in Computer Science.
    Now i have a problem, and i read something about the GOOP and the EXCEL Toolkit. I download it and try more times to install but i can't link the *.llb in the Function Palette. Is this GOOP and Excel Toolkit only for Labview 6.x ?
    I solve it with ActiveX and Excel, but my very big Problem is, i need to read2 string from the Excel table from the same time, and with ActiveX i don't find any method how can i do that.
    I don't know how can i read 2 Strings from a Excel table, Can i do it with the Excel Toolkit,if yes how, maybe anyone make it or any helpfiles?
    Thanks for your answer in advance ,
    Ender
    Ekinci

    "fuzzylogic" wrote in message
    news:[email protected]..
    > Hello,
    > i use Labview 5.1 with WIN NT4.0 SP6a and i programm a fuzzy Logic
    > tool for a exam in Computer Science.
    > Now i have a problem, and i read something about the GOOP and the
    > EXCEL Toolkit. I download it and try more times to install but i can't
    > link the *.llb in the Function Palette. Is this GOOP and Excel Toolkit
    > only for Labview 6.x ?
    >
    > I solve it with ActiveX and Excel, but my very big Problem is, i need
    > to read2 string from the Excel table from the same time, and with
    > ActiveX i don't find any method how can i do that.
    >
    > I don't know how can i read 2 Strings from a Excel table, Can i do it
    > with the Excel Toolkit,if yes how, m
    aybe anyone make it or any
    > helpfiles?
    I'm pretty sure the excel toolkit is written for 5.1, and don't know why it
    would give you problems. Do you have excel installed? I'm not sure what
    you mean that you cant link the *.llb in function pallette. Have you tried
    opening the llb using '\functions\select a vi' ? As to how to read two
    cells at once, you could read a block of cells including both cells (ie:
    A5..D10) and then pull the data out of the array.

Maybe you are looking for