run-time error 1004 on backup macro that worked before and works on other users - vba

I have a backup macro that runs every time when I save my excel file and saves a copy of the workbook into a folder.
Now I got a new computer where I use the same file, and it does not work anymore, I get run-time error 1004.
My co worker uses the same excel file and the same computer with another user and for him the macro works perfectly as it used to work for me on the other computer.
Code:
'backup
ora = ".h" & Hour(Now)
bufolder = ThisWorkbook.Path & "\excel_backups"
If Len(Dir(bufolder, vbDirectory)) = 0 Then
MkDir bufolder
End If
excfile = ThisWorkbook.Path & "\excel_backups\backup_" & Format(Date, "yyyy/mm/dd") & ora & "_" & ActiveWorkbook.name
If Dir(excfile) = "" Then
ActiveWorkbook.SaveCopyAs Filename:=bufolder & "\backup_" & Format(Date, "yyyy/mm/dd") & ora & "_" & ActiveWorkbook.name
End If
Edit: I get the error on line:
ActiveWorkbook.SaveCopyAs Filename:=bufolder & "\backup_" & Format(Date, "yyyy/mm/dd") & ora & "_" & ActiveWorkbook.name
It says:
Microsoft Office Excel cannot access the file '...'
There are several
possible reasons:
The file name of path does not exit. The file is being used by another
program. The Workbook you are trying to save has the same name as a
I don't think any of these problems may cause the problem.
Thank you for your time

The file cannot be saved because you are attempting to save the file name with your date formatted as "yyyy/mm/dd"? My computer will not allow me to save a file name with backslashes in it. Try changing the Format function to Format(Date, "yyyy-mm-dd").

Related

File is not saving to newly made folder in VBA

I have a macro that created a folder by data within a pathway, and I want a cut of a manager roster to be saved in that folder. Since the folder name varies, this needs to be dynamic.
I want it to go something like this:
Dim sPath As String
sPath = "M:\mgr1_TCR_Reports\"
If Len(Dir(sPath & "_" & Format(Date, "mm_dd_yyyy"), vbDirectory)) = 0 Then
MkDir (sPath & "_" & Format(Date, "mm_dd_yyyy"))
End If
End Sub
and saving this like:
.SaveAs Filename:="M:\mgr1_TCR_Reports\" & "_" & Format(Date, "mm_dd_yyyy_") & "\" & Manager, FileFormat:=xlOpenXMLWorkbook, Password:=""
.Close
But I keep getting a runtime 1004: document not saved on ^^^ the second line of code I provided.
Any idea what's going on?

Why i can connect to a sharepoint site with vba from one spreadsheet but not another

I have an odd issue where I can connect and upload files to a sharepoint site using a vba script, however using practically the same vba script from another spreadsheet and uploading to the same sharepoint site I can't connect and upload files.
The weird thing with the vba script that doesn't work is that if I add the below code to it before the rest of the script, the rest of the script works.
xPath= "https://teamspace.healthcare.siemens.com/content/90002613/Documents/"
With ActiveWorkbook
Application.ActiveWorkbook.SaveAs Filename:=xPath & Name & ".xlsm"
Application.ActiveWorkbook.Close False
End With
No idea why but xPath is a valid file path when using the SaveAs command, but when I use the same path or variant of it with the "Dir" tag it doesn't work and either give me a error code "Runtime 52 Bad File name or number" or "Runtime 76 path not found". Please can someone help with this, I have been trying everything I can think of for about the last 2 days
Thanks
Edit :
this is the code that works in one of the spreadsheets
If Dir("//teamspace.healthcare.siemens.com/content/90002613/Documents/GB_Invivo_RSM/" & xWs.Name & "", vbDirectory) = "" Then
MkDir ("//teamspace.healthcare.siemens.com/content/90002613/Documents/GB_Invivo_RSM/" & xWs.Name & "")
Else
End If
With ActiveWorkbook
Application.ActiveWorkbook.SaveAs Filename:=xPath & "\GB_RSM_P" & Format(LDate, "mm") & "FY" & Format(LDate, "yyyy") & " " & xWs.Name & ".xlsx"
End With
The code in the 2nd spreadsheet wont work unless I put another SaveAs() before all of this, and save a dummy spreadsheet, then have to delete it after, because obviously I don't want it there. I can't understand why the same code would work from one spreadsheet and not another, and also its almost like the saveAs() is creating a connection or something, but this wasn't needed in the 1st spreadsheet
If your URL is "https://teamspace.healthcare.siemens.com/content/90002613/Documents/" then you should be able to use Dir() as shown below:
Sub TestWebDAVDir()
Const MY_PATH As String = "\\teamspace.healthcare.siemens.com\content\90002613\Documents\"
Dim f
f = Dir(MY_PATH & "*")
Do While Len(f) > 0
Debug.Print f
f = Dir()
Loop
End Sub

VBA run time '1004' error when connected via VPN

I've searched through several forums and have found similar questions, but not my specific problem.
I have a macro that saves the active workbook to the specific user's folder, and saves a dated, xlsx, version in a sub folder. My macro-enable workbook is used by both in-office and remote associates. The in-office associates have no issue using this macro to save & archive the workbook to their folder, and, up until last week, the remote associates using VPN had no issues either.
However, over the past few days the remote associates using VPN have been receiving an error like run time error '1004': The specified dimensions are not valid for the current chart type and the code hangs on the ActiveWorkbook.SaveAs line at the end. Why would this error be coming up for a .SaveAs issue? I'm at a loss.
MainPath = "O:\Revenue Management\Centralized Revenue Management Service\CRMS Hotels\"
sPathSeek = MainPath & strPropNo & "*"
sFile = Dir(sPathSeek, vbDirectory)
sFileCheck = MainPath & sFile & "\Strategy Pack"
sBuildHist = MainPath & sFile & "\Strategy Pack\" & year1 & "\"
filePath = MainPath & sFile & "\Strategy Pack\" & propNo & " Strategy Pack.xlsm"
histPath = MainPath & sFile & "\Strategy Pack\" & year1 & "\" & propNo & " Strategy Pack " & STRdate & ".xlsx"
iLength = Len(Dir(sFileCheck, vbDirectory))
iLength2 = Len(Dir(sBuildHist, vbDirectory))
If iLength = 0 Then
MkDir (sFileCheck)
End If
If iLength2 = 0 Then
MkDir (sBuildHist)
End If
'Save Master Workbook
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs FileName:=filePath,
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
The file I am trying to save over is also a .xlsm file.
I've tried removing all charts.
I've tried re-saving the master file.
It's worth noting that the same day this started happening, my VPN access would not log in until our systems administrator unlocked it (which was a first)

Naming a workbook with a password

I am trying to figure out how to add a password to my workbook. The code does save it when I remove the password part ("sp17"), but I get a syntax error while its there. How would I correct this error?
ActiveWorkbook.SaveAs fileLocation degreeArray(criteria) & " " & format(Date, "MMM-YY") & ".xlsx", 51, "sp17"
I made a small change and now it works. The Format was written incorrectly. Thought about deleting my question but it was hard to find out how to do this so i'll leave it for any one who needs it. This was the right way to write it:
ActiveWorkbook.SaveAs fileLocation & degreeArray(criteria) & " " & Format(Date, "MMM-YY") & ".xlsx", 51, Password:="sp17"

Excel/VBA Remove text from ThieWorkbook.Name

I am trying to save a copy of an excel file through use of a marco but amend text after the current file name when saving. I have a macro that works, but it adds the file extension to the file name before I can amend text to it.
EG- my file is named "MyCurrentFile.xlsm", when I save it it adds the date, but keeps names the file "MyCurrentFile.xlsm01-14-16.xlsm".
Can I somehow remove the first .xlsm?
Code:
Sub Save_With_Todays_Date()
'
' Save_With_Todays_Date Macro
' Save a copy of the workbook with todays date at the end.
ThisWorkbook.SaveCopyAs _
Filename:=ThisWorkbook.Path & "\" & _
ThisWorkbook.Name & _
Format(Date, "mm-dd-yy") & ".xlsm"
End Sub
You can use the Workbook.FullName property and parse off the extension.
Dim fpfn as String
fpfn = ThisWorkbook.FullName
ThisWorkbook.SaveCopyAs _
Filename:=Left(fpfn, InStrRev(fpfn, Chr(46)) - 1) & Format(Date, "mm-dd-yy"), _
FileFormat:=xlOpenXMLWorkbookMacroEnabled
I would recommend leaving the extension off the Workbook.SaveAs method and let the XlFileFormat Enumeration assign the correct extension. Hardcoding the extension reduces functionality and can result in an incorrect extension being applied to a SaveAs.
ThisWorkbook.Name = Replace(ThisWorkbook.Name, ".xlsm", Format(Date, "mm-dd-yy") & ".xlsm")