VB script to open and close excel file without excel - excel

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

Related

Cannot update excel file using VBScript on SharePoint

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.

VBScript to Refresh Excel Data Connections (Trouble with Office 365)

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

Converting xls to csv but unable to close excel using vbs

I am using a VBScript to convert a xls file to csv. The process seems to be working how I need it except after the file gets converted my script won't close Excel. Both files remain open in excel preventing them from being updated or opened by other apps.
Here is the script I am using:
Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.DisplayAlerts = True
ExcelObj.Visible = false
ExcelObj.Workbooks.Open "P:\Pro2010\folder\Ovations\ovations.xls"
ExcelObj.Workbooks(1).SaveAs "P:\Pro2010\folder\Ovations\edited\company-JULY-TEST.csv", 6
OverwriteExisting
oExcel.Quit
When I open the file in Excel after the script has run it says "The file is in use by 'Another user'. Open a read Only?'
change
oExcel.Quit
to this
ExcelObj.Quit

Applescript Excel 2016 open as read only

I'm trying to get an Applescript to open a shared Excel file, but the read only function doesn't seem to work with the open alias syntax, am I doing something wrong?
Code similar to below.
set MasterFile to ""Macintosh HD:Users:myname:Desktop:Test File.xlsb"" as text
tell application "Microsoft Excel"
activate
open alias MasterFile with read only
end tell
Thanks,
VD
You need to open the file, set the read only recommendation, close workbook and open again. Without setting the display alerts you'll get a prompt asking whether to open as read-only.
Cheers!
set MasterFile to "Macintosh HD:Users:usrname:Desktop:Test File.xlsb" as alias
tell application "Microsoft Excel"
set display alerts to false
open MasterFile
set read only recommended of active workbook to true
save workbook
close active workbook
open MasterFile
set display alerts to true
end tell

Using VBS to open text file in excel and run macro without opening excel

This might sound confusing, and I'm not entirely sure it's possible to do it the way I want, but what I'm looking to do is create a script that will take a .txt file and run Excel macros on it, without actually opening up Excel or the file. One of the blogs I was reading suggested this method, but I'm not very familiar with VBS.
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Run "'Path\Test.xlsm'!Module.Macro"
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
This did not work when I tried to use it with a .txt file.
The error I receive is Cannot run the macro Path.... The macro may not be available in this workbook or all macros may be disabled
I'm sure it has something to do with my lack of VBS knowledge, but so far it's been the closest kind of script I've found for what I'm looking for. Is what I'm trying to do possible?
You need to open the workbook before you can run macros from it.
...
Set wb = objExcel.Workbooks.Open("C:\path\to\Test.xlsm")
objExcel.Application.Run "'Path\Test.xlsm'!Module.Macro"
...
You can't run a macro without opening Excel or the file containing the macro. If you want something like that you need to translate the VBA code to plain VBScript.
Path statement need full path eg " c:\ .... "
And I think it should be Module1.Macro_Name (not Module)
Write in note pad but save with .vbs on desktop. Just click on the run

Resources