VBA Copy/Paste Worksheet

MostafaAbdElKader

New Member
Joined
Sep 26, 2018
Messages
5
Hi All -

Having an issue with copying a worksheet and saving into destination on local drive with the data inside moved with all the equations and data validation - need to copy it only as a read only [No equations, No list] - values only -

Code:
On Error Resume Next


strDirname1 = "XYX"
strDefpath1 = "D:\YYY\"


MkDir strDefpath1 & strDirname1
strPathname1 = strDefpath1 & strDirname1 & "\" & MyFileName1




MyFileName1 = "NAME01 "
If Not Right(strPathname1, 1) = "\" Then strPathname1 = strPathname1 & "\"
If Not Right(MyFileName1, 4) = ".xlsx" Then MyFileName1 = MyFileName1 & ".xlsx"


Sheets("SERVICE SUPPORT TIME SHEET").Copy
With ActiveWorkbook
    .SaveAs Filename:= _
        strPathname1 & MyFileName1, _
        FileFormat:=51, _
        CreateBackup:=False
        .Close False




Workbooks.Open Filename:=strPathname1 & ".xlsx"
Workbooks(MyFileName1 & ".xlsx").Activate


          
    Workbooks(MyFileName1 & ".xlsx").Save
 Workbooks(MyFileName1 & ".xlsx").Close SaveChanges:=True


  


End With
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Welcome to the board. Try adding part in red:
Rich (BB code):
On Error Resume Next
    
    strDirname1 = "XYX"
    strDefpath1 = "D:\YYY\"
    
    MkDir strDefpath1 & strDirname1
    strPathname1 = strDefpath1 & strDirname1 & "\" & MyFileName1
    
    
    MyFileName1 = "NAME01 "
    If Not Right(strPathname1, 1) = "\" Then strPathname1 = strPathname1 & "\"
    If Not Right(MyFileName1, 4) = ".xlsx" Then MyFileName1 = MyFileName1 & ".xlsx"
    
    
    sheets("SERVICE SUPPORT TIME SHEET").Copy
    With ActiveWorkbook
        With ActiveSheet
            .Cells.Values = .Cells.Values
        End With
        .SaveAs Filename:=strPathname1 & MyFileName1, FileFormat:=51, CreateBackup:=False
        .Close False
        Workbooks.Open Filename:=strPathname1 & ".xlsx"
        Workbooks(MyFileName1 & ".xlsx").Close SaveChanges:=True
    End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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