From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
06-06-2017 10:09 AM
@sportsguy99 wrote:
I am not trying to open any file. I just need to make sure the Excel spreadsheet file is closed in the beginning of the program because the GUI will not append to the excel file without it being closed. I never open any files in this program.
If you're trying to read or write to the CSV, you're opening it. You wouldn't be having any of these questions if you weren't trying to open it.
06-06-2017 10:10 AM
@sportsguy99 wrote:
Yes, that the file is opened in Excel. How would i use OS calls? Is there any other ways? I would rather not make a pop-up message.
Even Windows Explorer uses a pop-up when you try to do something to a file that is opened in another process. This is a "User Error" and needs the User to choose what they really wanted to do. Keep the file opened in the other application or close the file over there and, open it for editing in this application.
Yes, you theoretically could grab a ref to the application that has the file opened and attempt to shut it down BUT, that will still likely throw a pop-up from that application asking if you want to save changes that you should not interfere with. Just let the user know they made a mistake.
06-06-2017 10:14 AM
The question I have been trying to ask, I might have made it a bit confusing is that the User who might use this program might have the Excel file opened and thus the GUI would not be able to append the file. I wish to make my program to close the Excel file at the start to prevent this. Yes, I can provide a popup, but wishing to just find a way to close the file.
06-06-2017 10:18 AM
@sportsguy99 wrote:
Yes, but I want to make my program robust in case of errors if another user uses the program. Just in case they have the file opened when running the GUI, i want my program to close the file.
Well there is making a robust program and there is trying to fix stupid.
You can't fix stupid.
If someone has the file open in Excel and then tries to open the same file in another program they are going to get a sharing violation message like the file is already open in another program.
That's just the way it is.
After they have to abort, close the file in Excel, and start over a few times they will get a clue.
06-06-2017 10:21 AM
They would not be trying to open it up again. The GUI just is not able to append to the file since it is already opened in excel. Is there any way to close the excel file at the start?
06-06-2017 10:28 AM
@sportsguy99 wrote:
They would not be trying to open it up again. The GUI just is not able to append to the file since it is already opened in excel. Is there any way to close the excel file at the start?
Yes, display a dialog to tell the user to close the file
06-06-2017 10:30 AM - edited 06-06-2017 10:30 AM
How about using something like this? i have been trying to implement it but I cant get the visible node. I found this example on another forum.
06-06-2017 10:32 AM
@sportsguy99 wrote:
They would not be trying to open it up again. The GUI just is not able to append to the file since it is already opened in excel. Is there any way to close the excel file at the start?
Well as people have suggested there is no easy way to close a file that Excel has open beyond finding the running Excel process and killing it.
Even doing that may not be seamless...
06-06-2017 10:33 AM
@sportsguy99 wrote:
How about using something like this? i have been trying to implement it but I cant get the visible node. I found this example on another forum.
That just pops up a prompt from Excel to save any changes to EVERY file that might be open in that application (Not just your csv)
06-06-2017 10:33 AM
Okay thanks. I will try to implement that solution if not, I will continue with a popup message