Save workbook into new workbook as values

Vtookup

Board Regular
Joined
May 30, 2017
Messages
137
Office Version
  1. 2016
  2. 2013
Hi all.
I hope to get help with saving workbook into new workbook as values. In the same directory. With the same file name of the workbook and the current date as file name.
Thanks in advance for the help.
 
Thanks Alex for your input. just hoping that in one go, turn NEW WB into values without asking user for password (all cells without formula and protection). Sorry I have poor comprehension with macros. Really helpless. Maybe( ) works fine. but when the original file is protected. Macro stop and won't convert.
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
without asking user for password
If you don't want to ask the user for the password then replace this
Rich (BB code):
pw = InputBox("Password Here")    '<---- Change required
with a line hard coding the password
Rich (BB code):
pw = "Hard_Coded_Password_In_Quotes"   '<---- Change required
 
Upvote 0
Hi Alex
We're talking about Post #18 right? Change
pw = InputBox("Password Here") '<---- Change required to
pw = "1234". my pw to all WS for this trial.
When tested on unprotected WS, the code run well. and all formula turn into values. Except all WS are PROTECTED. which is also okay.
When tested on Protected WS, the code stops and error 400.
Debugging stops at this code in my summary ws. Code for hidden picture that was assigned to clearcontents.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
Opinions?
 
Upvote 0
Give this a try:
It will only protect sheets previously protected and turns EnableEvents Off/On


VBA Code:
Sub Jolivanes_Mod()
    Dim newName As String, pw As String, wb As Workbook, sh As Worksheet
    Dim bHasPwd As Boolean
    
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    Set wb = ThisWorkbook
    pw = "123"    '<---- Change required
    newName = ThisWorkbook.Path & "\" & Left(wb.Name, InStrRev(wb.Name, ".") - 1) & Year(Now) & Format(Month(Now), "00") & Format(Day(Now), "00")     '& ".xlsx"    ', FileFormat:=51
    wb.Worksheets.Copy
    For Each sh In ActiveWorkbook.Worksheets
        bHasPwd = False
        If sh.ProtectContents Then bHasPwd = True
        sh.Unprotect pw
        sh.UsedRange.Value = sh.UsedRange.Value
        If bHasPwd Then sh.Protect pw
    Next sh
    With ActiveWorkbook
        .SaveAs newName & ".xlsx", 51
        .Close True
    End With
    
    Application.EnableEvents = True
    Application.ScreenUpdating = True

End Sub
 
Upvote 1
Alex,
LOOSEN UP. Everything is fine now.
just one small request, can we bypass the final message "To con't saving as macro-free WB -- Yes"
Jolivanes, Alex. You guys are the BEST.
Thank You for all your help.
 
Upvote 0
Please ignore the saving new document as macro-free workbook without prompt request. It's done.
Now, I have to rewrite some of my work that deals with PDF.
Regards and Thanks again.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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