Ok, so I have a bunch of excel workbooks, located in SharePoint, that are full of lookups etc and I want to write a macro that I can place in each that will:
So far I have mashed up a few different examples found here and have the following code. Unfortunately this is NOT saving the file correctly.
The output is being saved as "DesktopBOM Values Only15072024154934.xlsx" into the users H:/ drive not to the desktop, its CLOSE to working.
I did almost get the save to work, it saved to desktop but the naming was 'original filename'.xlsmDDMMYYHHMMSS.xlsx"
- Save the xlsm workbook before anything is done
- Remove any worksheet protection on all sheets (same passcode on all 9999)
- Copy everything
- make a new workbook
- Using the same filename as the original but with the word 'VALUES' + date and time amended (ie 'workbook name'_VALUES_DDMMYY_HHMMSS)
- Save it to the users desktop as XLSX
- Re-protect on all sheets in original workbook (same passcode on all 9999)
- Close the original workbook (new workbook can stay open)
So far I have mashed up a few different examples found here and have the following code. Unfortunately this is NOT saving the file correctly.
The output is being saved as "DesktopBOM Values Only15072024154934.xlsx" into the users H:/ drive not to the desktop, its CLOSE to working.
I did almost get the save to work, it saved to desktop but the naming was 'original filename'.xlsmDDMMYYHHMMSS.xlsx"
VBA Code:
Sub BOM Values Only()
Dim SavePath As String
Dim sh As Worksheet
Dim reopenWB as String
Dim calcMode As XlCalculation
'section start: remove protection
Dim wSheet As Worksheet
Dim Pwd As String
Pwd = 9999
On Error Resume Next
For Each wSheet In Worksheets
wSheet.Unprotect Password:=9999
Next wSheet
'section end: remove protection
‘SavePath = ThisWorkbook.Path & "\"
SavePath = CreateObject("WScript.Shell").SpecialFolders("Desktop")
reopenWB = Thisworkbook.FullName
With Application
calcMode = .Calculation
.DisplayAlerts = False
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
'save copy workbook as backup, just in case!
‘ThisWorkbook.SaveCopyAs SavePath & "Master_backup.xlsm"
ThisWorkbook.Save ' save just because belt n braces
'loop through sheets and set the used range to values
For Each sh In ThisWorkbook.Worksheets
With sh.UsedRange
.Value = .Value
End With
Next sh
'save as xlsx to remove macros
ThisWorkbook.SaveAs SavePath & "BOM Values Only" & Format(Now, "ddmmyyyyhhmmss"), xlOpenXMLWorkbook
'reopen the original file
Workbooks.Open (reopenWB)
'close the flat file
ThisWorkbook.Close False
With Application
.Calculation = calcMode
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub