The problem is I made a script that opens and refreshes data in my excel.
The data is external data from a PHD server I get this data with a plugin installed on excel.
All works fine untill I try to schedule the script with task scheduler. when I schedule it as "run only when user is logged on" it workes fine. but when I try to schedule it as " run wheter user is logged on or not" it does not update the data.
(it does open the excel and saves it but no changes in the data)
It is set on a VM that acts as a desktop and the updates need to be done even when i'm logged of.
The code of the script: (that works fine when i manualy launch it)
Dim oExcel
Set oExcel = CreateObject("Excel.Application") 'launch excel.
oExcel.Visible = True ' makes the aplication visible (if not set to true the data won't be updated)
oExcel.DisplayAlerts = False' disables all excel allerts.
oExcel.AskToUpdateLinks = False 'now excel will not ask you to update links.
oExcel.AlertBeforeOverwriting = False 'excel will not display an alert before overwriting data in a cell.
code for the plugin to update data
Dim addIn
addIn = COMAddIn
Dim automationObject
automationObject = Object
Set addIn = oExcel.COMAddIns("ExcelCompanion")
Set automationObject = addIn.Object
automationObject.UNIF_workbook_refresh
code to save and close excel
oWorkbook.RefreshAll 'refreshes the workbook
oWorkbook.Save 'saves the updated workoob
oWorkbook.Final = True 'makes the file read-only
oExcel.Quit 'exits excel
Set oWorkbook = Nothing ' destroy the object (minimises damage if the object goes out of scope)
Set oExcel = Nothing ' destroy the object (minimises damage if the object goes out of scope)
these 3 block of code form the script.
Hencky!
Which version of Windows do you have? I had the same problem about a week ago, and I came across a very strange solution... :)
Try adding a folder into C:\Windows\SysWOW64\config\systemprofile, simply named "Desktop"... If you run a 32-bit version of Windows, do the same thing except the path must contain system32 instead of SysWOW64...
The "run wheter user is logged on or not" will now do the work... If you had a logging function in your script, you would've seen that the script stops somewhere arround Excel commands... I don't know why is that so, it simply is...
Related
I have SharePoint 2010 and Office365.
I want an Excel spreadsheet, which has data from a SharePoint list to auto refresh every 1 min.
I tried to follow the procedure from the following blog
Here is the VBS code that I'm using:
Set xl = CreateObject("Excel.Application")
set wb = xl.WorkBooks.open("\\SPREADSHEET LOCATION\Sharepoint Pivot.xlsx",,TRUE)
xl.DisplayAlerts = False
WScript.Sleep 1000
wb.RefreshAll
wb.Save
wb.Close
xl.Quit
Then I created a task in Task Scheduler to run every minute.
Monitoring the progress in Task Manager, I can see that the file is being opened and it seems to work, but the data is not getting refreshed.
I have a feeling that this is because when the file is opened from SharePoint it's opening with the "Read-Only" message.
I thought that the code is taking care of that, but maybe it's not.
I wanted to debug the code by running one step at a time but I dont have access to cscript.exe
Am I doing something wrong here? I've looked around trying to find a solution but everyone seems to have the same code as above.
Thank you
I had a similar problem but found a solution - using .LockServerFile. See example code:
set xl = CreateObject("Excel.Application")
xl.Application.DisplayAlerts=False
set wb = xl.WorkBooks.open("location of excel file goes here")
WScript.Sleep 1000
xl.ActiveWorkbook.LockServerFile (only use if location is in Sharepoint to turn off edit mode)
wb.RefreshAll
wb.Save
xl.Application.DisplayAlerts=True
wb.Close
xl.Quit
I have a windows application written in vb.NET that pulls details from a big excel workbook and uses them to create site specific documents, depending on what site a user of the application has been assigned. The application then opens up the excel workbook it creates, and populates certain cells with the desired information, before opening a word document it has created to do similar.
The application was working perfectly for all users, but has recently stopped working for a user with Windows 8.1 and 32-bit Excel 2013. The application opens up the master excel workbook and pulls all necessary information from it, however when it tries to open the excel workbook it has created, it cannot proceed any further and eventually throws the following error:
The remote procedure call failed. (Exception from HRESULT: 0X800706BE).
The following is the code that opens up the master workbook, closes it, then copies the workbook template, renames it and finally opens it.
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Dim excelApp As Excel.Application = Nothing
Dim excelWB As Excel.Workbook = Nothing
Dim excelWS As Excel.Worksheet = Nothing
Dim fso As Scripting.FileSystemObject
Dim MasterLogLoc As String 'Path to the master workbook is stored in this string
Dim SiteTempLoc As String 'Path to the workbook template
Dim SiteWbLoc As String 'Path to the newly created wb
excelApp = New Excel.Application
excelWB = excelApp.Workbooks.Open(Filename:=MasterLogLoc, [ReadOnly]:=True, UpdateLinks:=False)
excelApp.Visible = False
excelWS = excelWB.Worksheets("Master")
excelWS.Select()
'Whatever details that are needed are grabbed
excelWB.Close(SaveChanges:=False)
excelApp.Quit()
excelApp = Nothing
excelWB = Nothing
'Next the template is copied and the newly created workbook is opened
fso = New Scripting.FileSystemObject
fso.CopyFile(Source:=SiteTempLoc, Destination:=SiteWbLoc)
fso = Nothing
'The application times out at the next part
excelApp = New Excel.Application
excelWB = excelApp.Workbooks.Open(SiteWbLoc)
excelApp.Visible = False
'The application times out at the above part
'Whatever needs to be done to the worksheet is completed
excelWB.Save()
excelWB.Close()
excelApp.Quit()
End Class
My computer is Windows 7, with Excel 2010 64-bit, and the application still works perfectly, it also still works perfectly on another Windows 7 computer.
The first time the user got this error, I got them to manually open up the workbook template, which showed that they did not have the file as a trusted document for their PC. After fixing this, they ran the application successfully but the next day the error appeared again, even though the workbook was now a trusted document.
The fact that the application opens up an already existing workbook successfully, but cannot open the workbook created on that PC, appears to be the main sign of the problem, however I am unsure where to proceed to next for troubleshooting this.
Could late-binding work? Or have I something missing from my code that makes the application more robust when operating on different versions of windows and excel?
I tried a late binding solution, however that didn't solve the problem, but I did manage to find a solution.
The excel worksheet the application copied had links to other excel worksheets - the links were outdated and not functioning correctly, which meant that every time the newly created worksheet was opened, a user had to select 'Enable Content' - not sure how I missed this!
I solved this problem by:
1) Fixing the links on the worksheet template being copied
2) Making the network drives, which held both the worksheet template and also the worksheets that the template had links to, trusted locations.
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 have my macro which is running, & for this I created a vb script and used windows task manager to schedule its run every day.
Whenever I run manually or attempt changing the time in the trigger, I always make sure that both excel and outlook are not running.
If I run the macro in Excel VBA, it sends the email.
After scheduling the task to run everyday, just as a test if I go to (in TaskScheduler) View -> Hidden Tasks and manually click Run, it sends the email.
However, if I schedule it to run at a specific time everyday, say maybe starting today, 15 minutes from now, it does not send the email & the last run result is (0x0).
I have enabled all macros in the trust center settings and selected 'Trust access to the VBA project object model', & it's not an issue about administrator privileges.
This is my VB script
Dim ObjExcel, ObjWB
Set ObjExcel = CreateObject("Excel.Application")
Set ObjWB = ObjExcel.Workbooks.Open("C:\Users\myUser\MyLocation\MyFile.xlsm")
ObjExcel.Visible = False
ObjExcel.DisplayAlerts = False
ObjExcel.AskToUpdateLinks = False
ObjExcel.AlertBeforeOverwriting = False
'vbs opens a file specified by the path below
'either use the Workbook Open event (if macros are enabled), or Application.Run
ObjExcel.Application.Run "MyFile.xlsm!main_macro"
ObjWB.Save
ObjWB.ActiveWorkbook.Close
ObjExcel.Quit
Set ObjWB = Nothing
Set ObjExcel = Nothing
WScript.Echo "Finished."
WScript.Quit
Also, here are my TaskScheduler Settings:
Ref:
Sending email from excel automatically based on date
How to set recurring schedule for xlsm file using Windows Task Scheduler
How can you run an Excel macro through a schedule task
Task Scheduler does not run Excel VBA Code to send PDF as Email Attachment
If I set the below to True:
ObjExcel.Visible = False
ObjExcel.DisplayAlerts = False
ObjExcel.AskToUpdateLinks = False
ObjExcel.AlertBeforeOverwriting = False
Excel opens in read-only mode and says click notify to receive the notification that you can now edit the workbook but I cannot edit it, says another user has the workbook open for editing.
I think the point is that the line
ObjWB.ActiveWorkbook.Close
must be
ObjWB.Close
.
Please try this and comment your results.
I am responsible for updating an Excel spreadsheet which pulls its information from an Access database on a daily basis. All the data that i need for my excel spreadsheet is available for me and all that i need to do is open the document, provide the password, enable to content and click the refresh button.
The database is very large and updating this during normal working hours causes problems as it slows down other users on the network. How would i use Windows Scheduler to do this for me outside of working hours? I'm not sure how to set up my script to follow my steps required.
I've had to do something quite similar to this recently, and with the help of this forum I've found something that works for me, and by the sounds of it may work for you too!
I created a notepad file with the following .vbs script
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oExcel.DisplayAlerts = False
oExcel.AskToUpdateLinks = False
oExcel.AlertBeforeOverwriting = False
Set oWorkbook = oExcel.Workbooks.Open("Full Path of your file.xlsx")
oWorkbook.RefreshAll
oWorkbook.Save
oExcel.Quit
Set oWorkbook = Nothing
Set oExcel = Nothing
What this does, it opens the file, refreshes any data connections, then saves the file and exits.
I then put this as a scheduled task to run at an off peak time, so that when the user opens the workbook, it's up to date.
I hope this helps!
I managed to achieve this through the VBA
hit Alt - F11
right click ThisWorkbook and click view code.
the code is as follows:
Private Sub Workbook_Open()
Workbooks.Open ("location of your workbook"), Password:="whatever your password is"
ThisWorkbook.RefreshAll
End Sub
i save this document and ask the task scheduler to run it at a specific time.