ShawnSPS
Board Regular
- Joined
- Mar 15, 2023
- Messages
- 61
- Office Version
- 2003 or older
- Platform
- Windows
Hello,
I am leaving you the above two codes. What I am trying to setup is a system variable for two of my Macros – one is called “Archive”& the other is called “SaveNextMonth”
The Idea is not have to hard code a path in the macro for each computer that the workbook is on. For those two Macros.
With the “Archive” Macro: I need it to save the zNotes worksheet into the folder called Archive Notes in the documents on the computer. and the clear the data with the range that I have give it. this is what I have write currently for “archive” how ever its not clearing out the data.
Sub archive()
Dim SavePath As String
ActiveSheet.Copy
SavePath = Environ("userprofile") & "\my documents\Archive Notes\zNotes.xls"
Application.DisplayAlerts = False
ActiveSheet.SaveAs SavePath
Range("b2:d5000").Clear
ActiveWorkbook.Close
End Sub
SaveNextMonth I haven’t got to it yet because of the issue with the “archive” Macro
But here is the current Macro: its basic the same concept that I need where the system variable is copying the workbook to a folder called Office Counts and then clearing out the data with the range I give it .. this Macro is current work but I don’t want to hard code a path – I want the system do to the work other I have go each computer and enter its path Manually which why the system Variable make more sense because it not OS dependant
Any direction would be helpful than you
Sub SaveNextMonth()
Application.ScreenUpdating = False
Dim mon As String, nextMon As String, fName As String, ws As Worksheet
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:="C:\Users\Shawn\Desktop\2023 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
I am leaving you the above two codes. What I am trying to setup is a system variable for two of my Macros – one is called “Archive”& the other is called “SaveNextMonth”
The Idea is not have to hard code a path in the macro for each computer that the workbook is on. For those two Macros.
With the “Archive” Macro: I need it to save the zNotes worksheet into the folder called Archive Notes in the documents on the computer. and the clear the data with the range that I have give it. this is what I have write currently for “archive” how ever its not clearing out the data.
Sub archive()
Dim SavePath As String
ActiveSheet.Copy
SavePath = Environ("userprofile") & "\my documents\Archive Notes\zNotes.xls"
Application.DisplayAlerts = False
ActiveSheet.SaveAs SavePath
Range("b2:d5000").Clear
ActiveWorkbook.Close
End Sub
SaveNextMonth I haven’t got to it yet because of the issue with the “archive” Macro
But here is the current Macro: its basic the same concept that I need where the system variable is copying the workbook to a folder called Office Counts and then clearing out the data with the range I give it .. this Macro is current work but I don’t want to hard code a path – I want the system do to the work other I have go each computer and enter its path Manually which why the system Variable make more sense because it not OS dependant
Any direction would be helpful than you
Sub SaveNextMonth()
Application.ScreenUpdating = False
Dim mon As String, nextMon As String, fName As String, ws As Worksheet
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:="C:\Users\Shawn\Desktop\2023 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