• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VB Code to save as file in folder with name from cell value

Ateeb Ali

Member
Dear Sir
I have a file and need to assign a vb code with a button.

When we click it, it should save the file with name "Range O6" "Sheet Summary"
All sheets are hidden except Summary at the moment
Hidden sheets including;
From Left to Right
"Consolidated Report", "Welcome", "New Style", "Garment Detail", "Picture", "Operations", "Machines Data", "Layout", "Report", "Summary", "Short"

I want save file in same binary format in same folder where original file exist and then to folder "TCS" (Folder already exist)

The saved file must have following unhidden sheets;
"New Style", "Garment Detail", "Picture", "Operations", "Machines Data", "Layout", "Report", "Summary"
The means Sheet "Consolidated Report", "Welcome" should be deleted in new saved file

Sheet "Short" should be hidden in new saved file.
The following buttons also be removed in saved files;
Sheet "Summary" Buttons "New" "Save Data"

Then we back again on original file without change, file attached
 

Attachments

  • Chandoo.xlsb
    313.1 KB · Views: 2
Last edited:
Dear Sir
This code working fine;
Code:
Sub filename_cellvalue()

For sh = 1 To Sheets.Count

Sheets(sh).Visible = -1

Next sh


  Sheets(Array("Consolidated Report", "Welcome")).Select

  Sheets("Consolidated Report").Activate

  ActiveWindow.SelectedSheets.Delete

  Range("J6").Select

  Sheets("Summary").Select

  ActiveSheet.Shapes.Range(Array("Button 554")).Select

  Selection.Delete

  ActiveSheet.Shapes.Range(Array("Button 556")).Select

  Selection.Delete


Sheets("Short").Select

ActiveWindow.SelectedSheets.Visible = False


'Update 20141112

Dim Path As String

Dim filename As String

Path = "C:\Users\ltpurc08\Desktop\Thread Consumption Software\TCS\"

filename = Range("O6")

ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsb", FileFormat:=50

End Sub

But it is showing message "Are you sure you want to delete as sheets have data"
So I want this message not to show and just happen the action.
Next thing I want not to jump on the save file and instead remain on existing sheet
 
UPDATE, This code finally worked, just one help needed now that it should return to original file after saving new saved file

Code:
Sub filename_cellvalue()
For sh = 1 To Sheets.Count
Sheets(sh).Visible = -1
Next sh

Application.DisplayAlerts = False
    Sheets(Array("Consolidated Report", "Welcome")).Select
    Sheets("Consolidated Report").Activate
    ActiveWindow.SelectedSheets.Delete
      Application.DisplayAlerts = True
   
    Sheets("New Style").Select
      ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete
    ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete
                ActiveSheet.Shapes.Range(Array("Button 170")).Select
    Selection.Delete
   
Sheets("Garment Detail").Select
      ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete
    ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete

Sheets("Picture").Select
      ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete
    ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete
   
    Sheets("Operations").Select
      ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete
    ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete
   
    Sheets("Machines Data").Select
      ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete
    ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete
   
    Sheets("Layout").Select
      ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete
    ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete
   
    Sheets("Report").Select
      ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete
    ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete
       
    Sheets("Summary").Select
      ActiveSheet.Shapes.Range(Array("ColorA3")).Select
    Selection.Delete
       
    ActiveSheet.Shapes.Range(Array("Button 554")).Select
    Selection.Delete
    ActiveSheet.Shapes.Range(Array("Button 556")).Select
    Selection.Delete
        ActiveSheet.Shapes.Range(Array("Button 627")).Select
    Selection.Delete
        ActiveSheet.Shapes.Range(Array("Button 555")).Select
            Selection.Delete
                ActiveSheet.Shapes.Range(Array("Button 553")).Select
    Selection.Delete

Sheets("Short").Select
ActiveWindow.SelectedSheets.Visible = False

'Update 20141112
Dim Path As String
Dim filename As String
Path = "C:\Users\ltpurc08\Desktop\Thread Consumption Software\TCS\"
filename = Range("O6")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsb", FileFormat:=50
End Sub
 
Back
Top