ShawnSPS
Board Regular
- Joined
- Mar 15, 2023
- Messages
- 61
- Office Version
- 2003 or older
- Platform
- Windows
I have expanded on my Archive Macro. In which the user does not have to create the subfolder “Archive Notes” in my documents, I added another Variable to allow it to Make the directory for the folder. I would like to do the same for “SaveNextMonth” Macro I am lost on how to include the new Variable. I have included both the working Macro for “Archive” and “SaveNextMonth” to see changes.
I need to add the 2nd Variable like I have above in “Archive Macro” to Make the directory folder “Office Counts” which the users do not need to create the folder the Marco will do that with the Variable. Please see “Archive Macro” I just don’t know where to begin on this one.
VBA Code:
Sub archive()
Dim SavePath As String, ArchivePath As String
ActiveSheet.Copy
SavePath = Environ("userprofile") & "\my documents\Archive Notes\zNotes.xls"
[COLOR=rgb(65, 168, 95)] ArchivePath = Environ("userprofile") & "\my documents\Archive Notes"
If Len(Dir(ArchivePath, vbDirectory)) = 0 Then
MkDir ArchivePath[/COLOR]
End If
Application.DisplayAlerts = False
ActiveSheet.SaveAs SavePath
ActiveWorkbook.Close
Range("b2:d5000").Clear
End Sub
I need to add the 2nd Variable like I have above in “Archive Macro” to Make the directory folder “Office Counts” which the users do not need to create the folder the Marco will do that with the Variable. Please see “Archive Macro” I just don’t know where to begin on this one.
VBA Code:
Sub SaveNextMonth()
Application.ScreenUpdating = False
Dim mon As String, nextMon As String, fName As String, ws As Worksheet, SavePath As String
mon = MonthName(Month(Date))
nextMon = MonthName(Month(Date) + 1)
If MsgBox("The current month will change to " & nextMon & " and all data from the previous month will be deleted. Are you sure you want to change the month and clear all data?", vbYesNo) = vbYes Then
fName = InputBox("Enter the file name to be used.")
If fName = "" Then Exit Sub
ActiveWorkbook.SaveCopyAs Filename:=Environ("userprofile") & "\my documents\Office Counts\" & fName & ".xls"
For Each ws In Sheets
If ws.Name <> "Ablank" And "ws.Name" <> "Zdata" And "ws.Name" <> "ZShortCuts" Then
With ws
.Unprotect ("Pila1DA.#")
.Range("A1") = nextMon
.Range("D3:AH31,D34:AH41").ClearContents
.Protect ("Pila1DA.#")
End With
End If
Next ws
End If
ActiveWorkbook.Save
Application.ScreenUpdating = True
End Sub