• 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.

Move a particular worksheet to a path

Mr.Karr

Member
Hello,

Can anyone please provide a code snippet to move/save a worksheet in a specific path?
Please improve the below code.

Requirement:
Before saving/after the save process, macro should move a particular sheet named "Data" to a specific path. Say... C://

Thanks in advance,
Karthik

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
        Cancel as Boolean)
   

End Sub
 
You might looking for this..

Code:
Option Explicit

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim myPath As String, MyFileName As String

Application.ScreenUpdating = False
Application.DisplayAlerts = False

myPath = "C:\Users\dEEPAK\Desktop\"
MyFileName = "CopySheet_Data.xlsx"

Sheets("Data").Copy
    ActiveWorkbook.SaveAs myPath & MyFileName ', FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    ActiveWindow.Close
   
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
 
how about this?
Code:
Sub sb_Copy_Save_Worksheet_As_Workbook()
Dim wb As Workbook
Set wb = Workbooks.Add
ThisWorkbook.Sheets("Data").Copy Before:=wb.Sheets(1)
wb.SaveAs "C:\Users\v-kart\Desktop\test\test1.xlsx"
End Sub

But I'm struck here how to rename the moved worksheet one by one with new names. There would be multiple users with different country names.

Is there a way to save as with a string in "A1" data tab please ? Many thanks
 
how about this?
Code:
Sub sb_Copy_Save_Worksheet_As_Workbook()
Dim wb As Workbook
Set wb = Workbooks.Add
ThisWorkbook.Sheets("Data").Copy Before:=wb.Sheets(1)
wb.SaveAs "C:\Users\v-kart\Desktop\test\test1.xlsx"
End Sub

But I'm struck here how to rename the moved worksheet one by one with new names. There would be multiple users with different country names.

Is there a way to save as with a string in "A1" data tab please ? Many thanks



Change these & check..

Code:
myPath = "C:\Users\v-kart\Desktop\test\" 'change as needed

MyFileName = Sheets("Data").[A1].Value & ".xlsx"
 
Back
Top