Method SaveAS ofobject_Workbook failed

Can an expert throw any light on this.

I use the below to save files without any problems.

Other colleagues also use without problems.

But some colleagues get the Methd SaveAs error.

I have noted that if the year [2015] file is in the folder it works for everyone every time

If the year is not in the folder it falls over with the error, so it is not creating the Year Folder.


Sub MonthFolder()
    Dim sFilename As String
    Dim sPath As String
     
    sFilename = "Test File " 'Set filename
 
    sPath = "C:\ABC\XYZ"       'Set base path"
   
    If Right(sPath, 1) <> "\" Then sPath = sPath & "\" 'Check for "\"
   
    sPath = sPath & Format(Date, "yyyy\\m mmm yyyy\\")
   
    If Dir(sPath, vbDirectory) = "" Then             'If folder doesn't exist, create it
        Shell "cmd /c mkdir """ & sPath & """"
    End If
    ActiveWorkbook.SaveAs sPath & sFilename & Format(Date - 1, " ddmmmyy") & ".xls"

End Sub
JagwarmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

als315Commented:
You can't create nested folders at once.
You should create Year folder and then Date folder:
Sub MonthFolder()
    Dim sFilename As String
    Dim sPath As String
     
    sFilename = "Test File " 'Set filename
  
    sPath = "C:\ABC\XYZ"       'Set base path"
    
    If Right(sPath, 1) <> "\" Then sPath = sPath & "\" 'Check for "\"
    
    sPath = sPath & Format(Date, "yyyy")
   
    If Dir(sPath, vbDirectory) = "" Then             'If folder doesn't exist, create it
        Shell "cmd /c mkdir """ & sPath & """"
    End If

    sPath = sPath & Format(Date, "\\m mmm yyyy\\")  
    If Dir(sPath, vbDirectory) = "" Then             'If folder doesn't exist, create it
        Shell "cmd /c mkdir """ & sPath & """"
    End If

 ActiveWorkbook.SaveAs sPath & sFilename & Format(Date - 1, " ddmmmyy") & ".xls"

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JagwarmanAuthor Commented:
so simple when you know what your looking for... Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.