how to save one sheet from a workbook in a specific folder with specific name

%3CLINGO-SUB%20id%3D%22lingo-sub-2416623%22%20slang%3D%22en-US%22%3Ehow%20to%20save%20one%20sheet%20from%20a%20workbook%20in%20a%20specific%20folder%20with%20specific%20name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2416623%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3EAnyone%20knows%20how%20to%20automatically%20save%20a%20specific%20sheet%20from%20a%20workbook%20%22Sheet%202%22%20in%20a%20specific%20folder%20with%20a%20specific%20name%20depending%20on%20the%20cell%20A7%20in%20%22Sheet%201%22%20with%20todays%20date%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2416623%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2416724%22%20slang%3D%22en-US%22%3ERe%3A%20how%20to%20save%20one%20sheet%20from%20a%20workbook%20in%20a%20specific%20folder%20with%20specific%20name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2416724%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1053100%22%20target%3D%22_blank%22%3E%40infinity94%3C%2FA%3E%26nbsp%3BLike%20this%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ESub%20SaveSheet()%0A%20%20%20%20Dim%20filename%20As%20String%0A%20%20%20%20filename%20%3D%20Worksheets(%22Sheet%201%22).Range(%22A7%22).Value%20%26amp%3B%20%22.xlsx%22%0A%20%20%20%20Worksheets(%22Sheet%202%22).Copy%0A%20%20%20%20ActiveWorkbook.SaveAs%20%22c%3A%5CYourPathHere%5C%22%20%26amp%3B%20filename%2C%20xlOpenXMLWorkbook%0A%20%20%20%20ActiveWorkbook.Close%20savechanges%3A%3DFalse%0AEnd%20Sub%0A%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2416817%22%20slang%3D%22en-US%22%3ERe%3A%20how%20to%20save%20one%20sheet%20from%20a%20workbook%20in%20a%20specific%20folder%20with%20specific%20name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2416817%22%20slang%3D%22en-US%22%3Ethank%20you%20for%20this%20but%20what%20if%20I%20have%20different%20drop%20downs%20in%20cell%20A7%3F%3CBR%20%2F%3ESo%20if%20in%20A7%20it%20says%20Dan%20I%20want%20to%20save%20it%20in%20one%20folder%3CBR%20%2F%3Eif%20A7%20says%20Ana%20I%20want%20to%20save%20it%20in%20a%20different%20folder.%20How%20would%20i%20do%20that%3F%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi all,

Anyone knows how to automatically save a specific sheet from a workbook "Sheet 2" in a specific folder with a specific name depending on the cell A7 in "Sheet 1" with todays date? 

6 Replies

@infinity94 Like this:

Sub SaveSheet()
    Dim filename As String
    filename = Worksheets("Sheet 1").Range("A7").Value & ".xlsx"
    Worksheets("Sheet 2").Copy
    ActiveWorkbook.SaveAs "c:\YourPathHere\" & filename, xlOpenXMLWorkbook
    ActiveWorkbook.Close savechanges:=False
End Sub
thank you for this but what if I have different drop downs in cell A7?
So if in A7 it says Dan I want to save it in one folder
if A7 says Ana I want to save it in a different folder. How would i do that?

@infinity94 You can use this of the path is in -say- A8:

 

 

 

Sub SaveSheet()
    Dim filename As String
    Dim filePath As String
    filename = Worksheets("Sheet 1").Range("A7").Value & ".xlsx"
    filePath = "c:\FirstPartOfPathHere\" & Worksheets("Sheet 1").Range("A8").Value
    If Right(filePath, 1) <> "\" Then
        filePath = filePath & "\"
    End If
    Worksheets("Sheet 2").Copy
    ActiveWorkbook.SaveAs filePath & filename, xlOpenXMLWorkbook
    ActiveWorkbook.Close savechanges:=False
End Sub

 

 

 

But you can also use regular cell formulas to build your won path and filename all in one cell and I'm sure you'll be able to figure out to use that in the code sample I gave
Thanks a lot for your help!
Actually I do have one more question... trying to add the date to the file name. 

added A9=(today)

and then changed code slightly but it just opens up the file with 2021 as name
Sub SaveSheet()
Dim filename As String
Dim filePath As String
filename = Worksheets("Sheet 1").Range("A7").Value & Range ("A9").Value & ".xlsx"
filePath = "c:\FirstPartOfPathHere\" & Worksheets("Sheet 1").Range("A8").Value
If Right(filePath, 1) <> "\" Then
filePath = filePath & "\"
End If
Worksheets("Sheet 2").Copy
ActiveWorkbook.SaveAs filePath & filename, xlOpenXMLWorkbook
ActiveWorkbook.Close savechanges:=False
End Sub
Doesn't that work? I'm that case try adding worksheet("Sheet 1") in front of it.