Sharepoint Locking Error when xlsm is Uploaded via VBA .SaveAs - excel

This VBA macro takes a template xlsm file saved on a shared drive and automatically uploads the file saved as with tomorrow's date in the title to SharePoint. It is triggered by a specific appointment reminder out of Outlook.
Although the file is saved to the SharePoint library, it seems to be locked for any kind of editing.
Error when trying to edit the file in browser:
Can't Lock File for Editing
Close
Error
We're sorry. We couldn't lock this file for editing. Would you like to try again?
Error when trying to edit properties in browser:
The file "http://sharepoint/TESTING FILE.xlsm" is locked for exclusive use by i:0#.w|"MyuserID".
Sub savetest()
Dim Template As Workbook
Workbooks.Open ("C:\MyFilePath\Name")
Set Template = Workbooks("Name.xlsm")
Template.SaveAs FileName:= _
"http://sharepoint/MyLibrary/MyFilePath/Name" &
Format(WorksheetFunction.WorkDay(Date, 1), "MM-DD-
YYYY") & ".xlsm?web=1" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled,
CreateBackup:=False
End Sub

Related

Run VB Script Externally

I have a VB Script or Excel Macro which I created and it works fine when I run the code from within Excel as an excel macro. But when I want to run it from Windows Explorer (i.e. save the text as a VBS script), I keep getting the Expected Statement error.
The code below essentially deletes two tabs from a template that I want to use, and then copies two tabs from another workbook to the template, and then saves that file. The code below was created using the record button in Excel. I am a total newbie to VBA, and so I do not know why the error is occurring. I do not also want to run the file from within Excel, because I want to be able to change the text what is in the macro. Thank you for your help.
Sub mapping_specs_comp_ss()
Set OrigMapTemplate = Workbooks.Open("D:\Kriss\Mapping Specs\Mapping Specs Template Version 3 - Copy Final.xlsx")
Application.DisplayAlerts = False
OrigMapTemplate.Sheets("QSTEST Mapping").Delete
OrigMapTemplate.Sheets("QSORRES Mapping").Delete
Set closedBook = Workbooks.Open("D:\Docs\Mapping Specifications\Automation\Mapping_Create - QSTEST QSORRES.xlsx")
closedBook.Sheets("QSTEST Mapping").Copy After:=OrigMapTemplate.Sheets("Visit Mapping")
closedBook.Sheets("QSORRES Mapping").Copy After:=OrigMapTemplate.Sheets("QSTEST Mapping")
closedBook.Close SaveChanges:=False
ActiveWorkbook.SaveAs Filename:= _
"D:\Docs\Mapping Specifications\Automation\Automated_Mapping_Specifications.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End Sub

How do I open a web link and save the file in the same folder?

I wish to write a VBA macro to open a web link and save the file in a folder. The following is my code:
Sub Performance()
Workbooks.Open "https://query1.finance.yahoo.com/v7/finance/download/XLY?period1=1411833600&period2=1569600000&interval=1d&events=history&crumb=jUHds.etlZC"
ActiveWorkbook.SaveAs ActiveWorkbook.Path & "/file.csv"
End Sub
However, the VBA macro doesn't work. Any idea what's wrong?

Simple SaveAs Excel Macro query - Need script updating to incl. filename and .xls extension

I have a excel worksheet order form that once completed, I need the end-user to click a button to save the worksheet, before then clicking an email link for sending.
I pulled a simple save script which works fine in bringing up a Save As dialog box, but I now need to add to it:
a) the name of saved file so I can save it as Trans_Order.xls
b) to save it as an .xls so the finished worksheet ideally doesn't contain the macro when sending over email to a 3rd party
Current code is:
Sub SaveAs()
Application.Dialogs(xlDialogSaveAs).Show
End Sub
Hope you can help - would be grateful for any assistance!
The xlOpenXMLWorkbook bit saves the file as a macro-free workbook. Application.DisplayAlerts = False suppresses an alert that fires saying that the Macro elements won't be saved. It will also suppress alerts about overwriting.
Application.DisplayAlerts = False
ThisWorkbook.SaveAs CreateObject("WScript.Shell").specialfolders("Desktop") _
& "\Trans_Order.xlsx", xlOpenXMLWorkbook
Application.DisplayAlerts = True
N.B. You may need to include the full path to the workbook in the double-quotes, or it will save back to the folder of your current workbook.

Save as CSV by macro - quiet mode - VBA 2010

I writing a macro to save the data in Excel sheet as CSV format - VBA 2010
I just have 2 issues at the end of the macro after everything is done.
1) In the command ActiveWorkbook.SaveAs I used the option ConflictResolution:=xlLocalSessionChanges to guarantee overwriting the file if exist in the same folder with the same name, this option should overwrite the existing file in quiet mode without asking the user if he wants to overwrite the existing file or not.
It was working in the below syntax
ActiveWorkbook.SaveAs Filename:="C:\File1.xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False, ConflictResolution:=xlLocalSessionChanges
And if a file with the same name was exist it was overwriting
But this option is not working although it was working for example when saving the file in normal Excel format but it is not working when saving as CSV.
But it is not working in the below syntax
ActiveWorkbook.SaveAs Filename:="C:\File1.csv", FileFormat:= _
xlCSV, CreateBackup:=False, ConflictResolution:=xlLocalSessionChanges
What I mean by 'It is not working' is that it is not overwriting the existing file and still displaying the message that there is a file with the same name exists and is asking the user if he wants to overwrite it or not.
As this is a macro so I don't want any interference from the user.
2) When I use the command ActiveWorkbook.Close to close the file after converting it to CSV, I have the message 'Do you want to save the changes (Yes/No).
I also want to save the file in quiet mode without having this message.
For the first part, add Application.DisplayAlerts = False right before you do the SaveAs and add Application.DisplayAlerts = True right afterward. That suppresses the overwrite message and automatically saves over the old file.
For the item 2, Try this:
ActiveWorkbook.Close False
It will close without the question.
Jair Batista

Unintended file dialog when updating links in Excel 2003 VBA

I'm keeping sets of interrelated Excel 2003 spreadsheets for each of my company's projects.
I want to copy some template XLS files to the project name and change the links that connect them to each other.
For example, the file TEMPLATE_ScanProgress.xls links to TEMPLATE_Film_Review.xls.
I am copying them both to 123456_ScanProgress.xls and 123456_Film_Review.xls, and updating the link in 123456_ScanProgress.xls.
Sample code of what I'm doing:
If Dir("WorkOrder & "_ScanProgress.xls") = "" Then
FileCopy "TEMPLATE_ScanProgress.xls", WorkOrder & "_ScanProgress.xls"
Workbooks.Open Filename:=WorkOrder & "_ScanProgress.xls", UpdateLinks:=0
ActiveWorkbook.ChangeLink "TEMPLATE_Film_Review.xls", _
WorkOrder & "_Film_Review.xls", _
xlLinkTypeExcelLinks
Workbooks(WorkOrder & "_ScanProgress.xls").Close SaveChanges:=True
Else
FileExists = True
FileExistsWarning_7 = WorkOrder & "_ScanProgress.xls"
End If
The problem is that when the code tries to update the link I get a file dialog asking me to choose a file for the change, even though I already specified which file I want in the code.
Try setting DisplayAlerts to False. DisplayAlerts is on the Application object and is used to suppress dialog boxes for example when overwriting a file. It may work in this case too.

Resources