Open excel from powershell not in read-only to allow manual editing - excel

My script currently scrapes some web data and places it into an excel file. However, I need to manually edit some fields before the script continues on.
My question is, once Ive scraped the data into excel, how do I open the application (with my new workbook) and allow editing?
I’ve tried start-process excel.exe but it opens with a read-only warning.
Thank you

Excel as an application always can do read and write. The question is if the file you are trying to open can be read-only. A read-write file can become read-only when emailed or downloaded. it is the file you want to check.

Related

Can I programmatically enable and disable ms-excel file sharing / co-authoring of an xlsx file stored in SharePoint and linked to ms-access?

We have a ms-excel xlsx file stored in SharePoint. This file can be edited in two ways: directly in SharePoint or through ms-access acting as a front-end of the xlsx file (as an external linked table). We want the xlsx file to be edited while the ms-access database is open.
While ms-access is open, the xlsx file appears as read-only. We want programmatically disable the read-only state, so that other people could edit the xlsx file while ms-access is open and, also, enable read-only again when necessary.
I think that the only way to get this is by sharing the xlsx file. My question is as follows:
I don't know whether the best way to share the xlsx file is using co-authoring or using the standard ms-excel sharing. We tried to do it manually using co-authoring, but the xlsx file could not be edited through ms-access.
If we manage to edit the xlsx file through ms-access, then, is it possible to change the shared status programmatically while ms-access is open throug VBA, .NET, VSTO, MS-Javascript API or any other language? I have searched in Google, but I have found nothing but some .NET library for ms-word (Microsoft.Office.Interop.Word.CoAuthoring), but, curiously, not for ms-excel and, as the great wise Confucius said, "if you search something in Google for more than three hours and you don't find it, this means that it doesn't exist".
But maybe someone has had this same odd problem and could help us.
Thanks in advance.
You can't. The first application to open the file will "hold" it, and the next will either could open it as read-only or not at all.
You may be able to let Access open the Excel file, import the data to a table, and then close the file. If the file already is opened in Excel, it may fail, and that you must, of course, take care of.
Another option could be to have a function in Excel that exports the data to another workbook, and then let Access read this.

Excel VBA: how to capture event of ca change in read-only setting? Excel file is opened over SharePoint and automatically set to read-only

I have an *.xlsm file that is to be accessed department-wide over SharePoint. The problem is when this file is opened it is open in read-only automatically (presumably because of SharePoint settings). The prompt at the top of the window is :
Server Read-Only This workbook was opened from a server in read-only mode. [Edit Workbook]
I know how to capture the read-only setting when the file is opened and to configure my file accordingly
I know how to prompt the user to change the read-only setting when the workbook is being opened.
This is my problem:
I don't know how to capture the event when a user presses [Edit Workbook] and the file is no longer read-only.
My only workaround is to constantly check the read-only setting of the file at every execution of any code, which I'd rather not do because of performance hit and it might not always work.
So I'm stumped. Any ideas on how to capture this event?
I found my answer.
When the file is opened over SharePoint, the file is automatically opened as read-only with a yellow prompt asking the user if the file is to be edited.
The command ThisWorkbook.LockServerFile will behave just as if [Edit Workbook] had been pressed. Placing it in the Workbook_Open() Event will execute this command every time this file is opened. The problem is that if this command is executed on a local drive, this will return an error, so you need to have some error handlers or detect your environment.
This is a link to the MSDN article:
https://msdn.microsoft.com/en-us/library/office/ff838567.aspx

Excel vba open read only file error

I have a vba macro to open Excel files, including Read-only files.
I use the following code to do this:
Workbooks.Open((FileName:=MyFileName, UpdateLinks:=0, IgnoreReadOnlyRecommended:=True)
Up until June 2013 this never failed. As of now this no longer works. Now when the macro encounters a read-only file the file appears in a separate window and a Save As prompt also appears (never happened before).
If I click Cancel I get a Path not found error. If I click Save the file gets saved to its original location. This is completely new. There is no Save As command in this part of my code.
It appears to be something new associated with Microsoft’s File > Protect Workbook > Mark as final stuff. Anyone seeing this? I can’t find a way to prevent it. I simply want to be able to open the read only file without further prompts.
I haven't used VBA with excel much, but is it possible that the macro security settings within excel were reset so that it no longer trusts macros or VBA script attempting to use it.
Thanks for the input. I did find a work-around. In newer versions of Excel there is a new ReadOnly designation: Final, i.e. File > Protect workbook > Mark as Final. This is the same as ReadOnly, just by another name, and it does not show up as an option in WorkBooks.Open(FileName:= ...). If I set the Workbook.Final property = False, then I can open the file w/o the SaveAs prompt.
If wbName.Final = True Then
wbName.Final = False
End If

Recover unsaved .csv file changes

Does anyone know a way to recover changes made in a .csv that were not saved when excel 2007 was closed.
At the moment, I don't see any way to solve this.
Check all the temporary files created recently. Especially alongside the file you opened. There are a few temp folders in the system that Excel may use. C:\Windows\temp is the main one, but it is usually under the Users folder in later versions of windows. Eg: C:\Users\YourUserName\Local Settings\Temp
If you find any files that look like Excel temps, take a copy and rename the extension and then try to open it.
(Your only real chance is if auto-save kicked in and saved a copy - to a temp file - when you still had your new changes in the document. Otherwise the changes are lost I'm afraid)
If option #1 doesn't resolve your problem in Excel, go to File->Options->Save. Hopefully your AutoRecover file location, under the third box, will be populated with an address.

Is this possible in Excel: Open XLS via commandline, OnLoad import CSV data, Print as PDF, Close Doc?

Thinking that to solve a problem I've got this is the fastest solution:
Generate a custom CSV file on the file (this is already done via Perl).
Have a XLS document opened via commandline via a scripting language (clients already got a few Perl scripts running in this pipeline.)
Write VBA or record a macro that executes the following OnLoad:
Imports a the data from the CSV file into the report template,
Print the file via PDF driver to fixed location using data in the CSV to name the file.
Closes the XLS file.
So, is this possible via Excel macros, if not is it possible via VBA -- thanks!
NOTE: Appears I've got to have a copy of MS Office anyway, so this is much faster to get going than using Visual Studio Tools for Office (VSTO). The report template is going to be on a server, and this way the end user can build as many reports as they like, "test" by printing a PDF using a demo CSV file, and import/embed the marco or VBA when they're done. I'd looked in Jasper Reports, but the end user is putting ad-hoc static text and groupings all over the report and I figure this way they can build reports how ever they want and then automate them. Both of these questions by me and the resulting comments/feedback are related to this question:
In Excel, is it possible to automate reading of CSV data into a template and printing it to PDF from the commandline?
Is it possible to deploy a VB application made in Excel as a stand alone app?
FOCUS OF QUESTION: Again, focus of the question is if this is possible via Excel marcos, if not macros VBA, and if there's any huge issue with this approach; for example, I know this is going to be "slow" since Excel would be loaded per job, but there's 16GB of ram on the server and it's not used at all. Figure since I've got to have a copy of office on the server anyway, this is a much faster approach.
If you've got any questions, let me know via comments.
I suppose you could launch the report file from perl and then have a macro inside the report file automatically look for the newest csv file to import. Then you could process and output. So you just need to launch the proper excel file with the embedded macros from perl and then let excel and VBA take over.

Resources