![]()
Sub SaveAsValues() 'Save Monthly Report as Values in new workbook Dim newWB As Excel.Workbook Dim wks As Excel.Worksheet Dim vSheets As Variant Dim varName As Variant Dim DVItem As Range Dim counter As Long '---------------------------------------------- Application.DisplayAlerts = False Application.ScreenUpdating = False 'Define the names of worksheets to be copied. vSheets = VBA.Array("FTE Variance (8)", "Mill Levy Summary (7)", "Spending Graph (6)", _ "Forecasting Tool (5)", "16-17 Full Year (4)", "16-17 YTD (3)", _ "16-17 Current Month (2)", "Remaining Balance (1)", "Monthly Report Cover Page") For Each DVItem In ThisWorkbook.sheets("Config").Range("O16:O159").Value ' Loop DV list ThisWorkbook.sheets("Config").Range("C2").Value = DVItem.Value 'Create referenece to the destination workbook. Set newWkb = Excel.Workbooks.Add newWkb.Connections.AddFromFile _ "C:\Users\PAUL_CYR\Documents\My Data Sources\fin-dmart-prod LAWSONDW GL SUMMARY CUBE.odc" For Each varName In vSheets 'Clear reference to the [wks] variable. Set wks = Nothing 'Check if there is a worksheet with such name On Error Resume Next Set wks = ThisWorkbook.Worksheets(VBA.CStr(varName)) On Error GoTo 0 'If worksheet with such neam is not found, those instructions are skipped. If Not wks Is Nothing Then 'Copy this worksheet to a new workbook wks.Copy After:=newWkb.Worksheets(1) Application.CalculateUntilAsyncQueriesDone 'Get the reference to the copy of this worksheet and paste 'all its content as values With newWkb.Worksheets(wks.Name).UsedRange .Value = .Value End With End If Next varName newWkb.SaveAs Filename:="H:\1_School Support\RBR FY17\Monthly Reports\October\" & Range("B1").Text & " - Monthly Report - October.xlsx" newWkb.Close SaveChanges:=False counter = counter + 1 Next DVItem Application.DisplayAlerts = True Application.ScreenUpdating = True MsgBox counter & " reports saved. ", , "Monthly Reports Complete" End Sub
Bookmarks