• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 67
  • Last Modified:

vba to save file using reference from cell in sheet

could an expert help me out with the code to save a file using the data in cell C36 to create the name of the file. I also need the vba to save the file in a folder where year will change and month will change, so:

file name is taken from Cell C36 [i.e.Part Red Rec 1234]

Path is:  G:\Cpn\CA\Events\Partial\current\current month\file name

Year is current year [If folder doesn't exist, create it]

Month is Current Month [i.e. Mar 15] ... [If folder doesn't exist, create it]

Result would be Save file as:

G:\Cpn\CA\Events\Partial\2015\Mar 15\Part Red Rec 12345

1 Solution
Rory ArchibaldCommented:
For example:

Sub SaveMe()
Const csROOT_PATH As String = "G:\Cpn\CA\Events\Partial\"

If Dir(csROOT_PATH & Year(Date), vbDirectory) = vbNullString Then
    MkDir csROOT_PATH & Year(Date)
End If
If Dir(csROOT_PATH & Year(Date) & "\" & Format(Date, "mmm yy"), vbDirectory) = vbNullString Then
    MkDir csROOT_PATH & Year(Date) & "\" & Format(Date, "mmm yy")
End If
ActiveWorkbook.SaveAs Filename:=csROOT_PATH & Year(Date) & "\" & Format(Date, "mmm yy") & "\" & ActiveSheet.Range("C36").Value & ".xlsm", FileFormat:=52

End Sub

Open in new window

JagwarmanAuthor Commented:
brilliant thanks
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now