VB Code to save as file and return to original file

ateebali

Board Regular
Joined
Dec 13, 2018
Messages
108
Dear Sir
I am using following code to save as file as cell value name, its working fine, I just need to be on same original file again after this code

Dim Path As StringDim filename As String
Path = "C:\Users\ltpurc08\Desktop\Thread Consumption Software\TCS"
filename = Range("O6")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsb", FileFormat:=50
Application.DisplayAlerts = True
ActiveWorkbook.Close

The original file should not be closed
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Perhaps something like this

Code:
Sub SaveWB()
    Dim Path As String
    Dim FileName As String
    Dim FilePath As String
    Dim DestWB As Workbook

    Path = "C:\Users\ltpurc08\Desktop\Thread Consumption Software\TCS"
    FileName = Trim(CStr(Range("O6").Value))

    If Not Left(FileName, 1) = "\" Then
        FileName = "\" & FileName
    End If

    If InStr(FileName, ".") > 0 Then
        FileName = Left(FileName, InStr(FileName, ".") - 1)
    End If

    FilePath = Path & FileName & ".xlsm"

    Application.DisplayAlerts = False
    ThisWorkbook.SaveCopyAs (FilePath)
    Set DestWB = Application.Workbooks.Open(FileName:=FilePath)

    DestWB.SaveAs FileName:=Path & FileName & ".xlsb", FileFormat:=50

    Kill FilePath
    DestWB.Close
    Application.DisplayAlerts = True
End Sub
 
Upvote 0
Dear Sir,
The code not working, see below my original code, it do everything right like save new file which I required, I just want it not to close original file and return on it;

Also help to simplify the 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


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


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


'Update 20141112
Dim Path As String
Dim filename As String
Path = ThisWorkbook.Path & ""
filename = Range("O6")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsb", FileFormat:=50
Application.DisplayAlerts = True
ActiveWorkbook.Close
End Sub
 
Last edited:
Upvote 0
Finally this works
Dim Path As StringDim filename As String
Path = ThisWorkbook.Path & "\Backup" & ""
filename = Range("O6")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsb", FileFormat:=50
Application.DisplayAlerts = False


ChDir "\\selfs1\Thread Consumption"
Workbooks.Open filename:= _
"\\selfs1\Thread Consumption\Thread Consumption.xlsb"
Windows("Thread Consumption.xlsb").Activate

ActiveWindow.ActivateNext


ActiveWorkbook.Close
I just need one help now, instead of this;
ChDir "\\selfs1\Thread Consumption"Workbooks.Open filename:= _
"\\selfs1\Thread Consumption\Thread Consumption.xlsb"
Windows("Thread Consumption.xlsb").Activate

I want system to open same file without fixing it so when we change original file location, it open the correct file always.
I dont want to put file path like this, it should detect by itself
 
Upvote 0
Finally this works

I just need one help now, instead of this;

I want system to open same file without fixing it so when we change original file location, it open the correct file always.
I dont want to put file path like this, it should detect by itself

I'm glad you found a solution that works for you; however the problem you describe is one the code I posted would have solved. Perhaps someone else will have a different suggestion.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top