Need help understanding VBA
Hello people of the MS forum,
Need a help understanding and applying it to different workbooks. The below VBA was given to me by my predecessor and didn't leave too much details on how to write the script. I'm not good at VBA by any stretch but my manager wants me to mimic the same using a different newly created workbook. I tried copying the script but can't make it do the same.
Sub Copy_Sheets_To_New_Workbook()
Dim wb As Workbook, sh As Worksheet, DateString, D, Value, Act As String
Dim Path As Variant, L, x As Long
Application.ScreenUpdating = False
Set wb = ThisWorkbook
Path = ThisWorkbook.Path & ""
Value = wb.Sheets("Raw Data").Cells(1, 1)
DateString = Left(Right(Value, 18), 2) & "-" & Left(Right(Value, 15), 2) & "-" & Left(Right(Value, 12), 2)
'Copy specified sheets to new workbooks
For L = 1 To 6
wb.Activate
Set sh = Worksheets(L)
sh.Select
Application.CutCopyMode = False
sh.Copy
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Act = sh.Cells(1, 1)
ActiveWorkbook.SaveAs Filename:= _
Path & "MTD - " & Act & " " & DateString & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Next L
wb.Activate
ActiveWorkbook.SaveAs Filename:= _
Path & "MTD - " & DateString & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.ScreenUpdating = True
End Sub
|