I have an excel workbook that currently has a macro built into it that when pressing the macro's button, the current workbook is saved to a directory that the macro creates and the template is then wiped clean in order to make room for the next day's data.
Instead of this macro saving the entire workbook as a new file that then has to be tracked down to be viewed, I would like to edit the macro to do the following:
Here is the code:
Sub NewDay()
Dim fn, d, ln
Set fs3 = CreateObject("Scripting.FileSystemObject")
Set fs = CreateObject("Scripting.FileSystemObject")
If fs3.FolderExists("c:\Morning Reports\") = True Then GoTo ext Else GoTo mkdir:
mkdir:
Set d = fs.CreateFolder("c:\Morning Reports\")
With Application
.UserName = "MD Totco"
.StandardFont = "Arial"
.StandardFontSize = "10"
.DefaultFilePath = "c:\Morning Reports\"
.EnableSound = False
.RollZoom = False
End With
ext:
Sheets("Morning Report").Select
ActiveSheet.Unprotect
ChDir "c:\Morning Reports\"
tempdate = ActiveSheet.Range("w1") + 1
ActiveSheet.Range("w1") = tempdate
tDate = Format(tempdate, "mmm d yyyy")
WellName = ActiveSheet.Range("s2")
fName = tDate + ", " + WellName
ActiveWorkbook.SaveAs FileName:=fName
This would be the section within Sub NewDay that is creating the new file and saving, the rest of the code is wiping and refreshing the template. However, I do not want the workbook to be saved, I just want the "Morning Report" sheet of the workbook to be copied over to a new sheet.
Copying a worksheet is easy:
Public Sub copy()
Sheets(1).copy after:=Sheets(1)
End Sub
The remainder should be easy for you to figure out.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.