I have the following simple VBScript for updating an Excel workbook.
Dim objExcel
Set objExcel = CreateObject("Excel.application")
objExcel.DisplayAlerts = False
objExcel.Visible = False
objExcel.Workbooks.Open "path\myworkbook.xlsx"
objExcel.ActiveWorkbook.RefreshAll
objExcel.ActiveWorkbook.Save
objExcel.Quit
Set objExcel = Nothing
When I use path to local excel file like C:\Users\sbrbot\Documents\myworkbook.xlsx the script works and updates my excel workbook fine. But when I use the remote path like \\sharepoint\library\myworkbook.xlsx then script executes without errors (so path is correct) but the workbook is not really updated! (SharePoint version 2013). Even if I map SharePoint's remote server path \\sharepoint\library to logical M:\ drive, and my path is M:\myworkbook.xlsx the same is hapening, it does not update workbook. Seems like SharePoint refuses to update file. Path is correct, that's not the problem.
I have to mention one strange bahaviour with SharePoint. When I manually open Excel file from SharePoint remote directory, make some changes in it, and save the file - in Excel's titlebar it is reported as Saved. Immediately after this when I go to close this Excel file, Excel asks me to save it again although I did not change anything inside the file.
Related
I need to run automatically an excel macro that PDFs a monthly report and then saves and closes the excel file. My proposed solution is that using Windows Task Scheduler it runs a windows batch print file that runs a VBScript which then runs the excel file. The excel file when it is open then runs a macro that PDFs what I need. All of this I have tested many times locally on my PC and all of it works fine. Now this all needs to run on a remote desktop that is a virtual machine. This is where the issue happens. Everything runs fine up until it opens the excel file, the excel file opens in the background and its icon on the task bar flashes orange, because of this nothing else happens. The macro breaks and does not print, it doesn't even start in the first place. Is there any ideas on how to fix this? Here is the coding for the VBScript that opens the excel file.
Dim args, objExcel, openExcel
Set args = wScript.Arguments
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open args(0)
objExcel.Visible = True
objExcel.Run "ReportPrint"
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close(0)
objExcel.Quit
I have a large Excel file that uses PowerPivot to connect to several external data sources. The Excel file is stored in a SharePoint folder. I would like to be able to refresh the connections automatically overnight. To do this, I am using Windows Task Scheduler to trigger a VBScript each day at 2AM.
Previously, I had the script run a macro within the workbook to refresh all. This worked successfully until my organization recently updated to Microsoft Office 365 ProPlus. I am now struggling with the new read-only default setting for SharePoint. Following the update, whenever I open an Excel file from SharePoint, I see a yellow bar reading "Read-Only: We opened this workbook read-only from the server. Edit Workbook". When working with files manually, this has to be clicked before changes can be saved. I tried to research the programmatic workaround for this and found the recommendation to use the method .LockServerFile.
To streamline the trouble-shooting, I have tried to move the entire action into the VBScript script, rather than running a macro within the workbook. My code is below.
When I watch the process, the yellow "Read-Only" bar appears to pop up immediately before the save. I can run the process once with no apparent errors, but if I then manually open the file, I don't see the option to "Edit Workbook". If I manually change the file, save, and then run the script again, I get the error 800A03EC.
It seems that somehow the script is failing to correctly "release" the lock on the server file after it finishes.
Is there a way to fix this?
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("[[The Sharepoint Path]]")
objExcel.Application.DisplayAlerts = False
objExcel.Application.Visible = True
objExcel.ActiveWorkbook.LockServerFile
objExcel.ActiveWorkbook.EnableConnections
objExcel.ActiveWorkbook.Sheets(1).Range("P2").Value = Date
objExcel.ActiveWorkbook.RefreshAll
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close false
objExcel.Application.Quit
set objworkbook = Nothing
set objExcel = Nothing
WScript.Quit
I needed a way to schedule automatically opening an Excel file, refresh the contents then save and close it.
I have done this before but I can no longer open the file as opening it causes the macro that refreshes then saves and closes the file to run.
I considered VBScript after trying several ways of doing it. I found this code on here.
Dim objExcel, objWorkbook
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\...\Finances.xlsm")
objExcel.Visible = True
objExcel.Run "Refresh"
objExcel.Quit
Set objWorkbook = Nothing
Set objExcel = Nothing
WScript.Quit
The VBScript code opens the Excel file and triggers the macro Refresh inside. The macro refreshes the data then saves and closes the file.
But I'm getting the following error despite the code seeming to run ok.
If you don't want anything to run automatically when you open the workbook, put the line
objExcel.EnableEvents = False
before you open the workbook. You could set it back to True later if you need to. You should still be able to run Refresh. Whether or not that will fix your unknown error, I don't know.
You are quitting the excel.application object without closing the objWorkbook open workbook. Saved or not, this is going to generate an error crashing out of the open workbook.
Below a VBS code converts .xls into .csv.
Set oBook = oExcel.Workbooks.Open(sfile)
oBook.SaveAs fulldest, 6
oBook.Close False
If works fine for most files but one of them has the usual Excel found unreadable content in filename.xls'. do you want to recover the contents of this workbook ? If you trust the source of this workbook, click Yes..
When the .Workbooks.Open method executes for this file, I get Unable to get the Open property of the Workbooks.
I tried oExcel.Workbooks.Open(sfile, xlRepairFile) without success.
I want to open and save an excel file in sharepoint, which has no excel installed. I tried to write an vbscript but I only can find which called excel application. Please help to advise. Thank you!
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("D:\Roambi\Test excel\Test.xlsx")
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
WScript.Quit
I am not sure about the reason of the issue, but if you need open and modify some content - maybe Open XML SDK could help. However if you need to open to run some script inside that file - you'll need to have installed Excel application