Good afternoon all,
I have a spreadsheet, where I would like the code to automatically use 2 fields to create the file name for saving the file to a SharePoint site.
The code I have is as follows:
Sub Post_Req()
' To save document to SharePoint, using the file name and Submit date fields to create save file.
Dim SubDte, Title, FileName, FolderName, FullFileName
Application.DisplayAlerts = False
SubDte = Worksheets("Request Form").Range("G6").Value
Title = Worksheets("Request Form").Range("I6").Value
FileName = Title & "-" ' & SubDte
' Location for Requests to be saved to
FolderName = "C:\Users\xxxxxxx\Desktop\FLS\Projects\SharePoint Workflows\Rework\" ' Test location
' FolderName = "http://xx.xxxx.xxx.com/xxx/xxxx/xxx/Rework/" ' Live location
FullFileName = FolderName & FileName
ActiveWorkbook.SaveAs FileName:=FullFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=True
MsgBox "Request posted, document name " & FileName & ".xlsm" & vbCrLf & vbCrLf & "" & vbCrLf & "Approval Workflow now started in SharePoint"
Application.DisplayAlerts = True
' ThisWorkbook.Close (False)
End Sub
Cell G6 is a Date field and usually would be in dd/mm/yyyy format but I am aware that ' / ' are not allowed when saving a file in Excel. I then tried to use a custom format dd-mm-yyyy in the cell but VBA is still recognising this as a Date format and fails.
If I remove the requirement for SubDte to be used in the file name, it saves perfectly to my test environment. (e.g. FileName = Title & "-" ' & SubDte)
Ultimately, my goal is to create the file name based on 2 fields - one being a text string and the other being the submit date of the request.
Any help in correcting my code to achieve this is very much appreciated.
Thank you,
Chris
Bookmarks