Macro not working.

Robert Wyatt

Board Regular
Joined
Jul 15, 2012
Messages
84
Office Version
  1. 2019
Platform
  1. Windows
I have a macro that has stopped working correctly and I'm at my wits end. It says it has either been moved, no longer exits or another program is using it. But I have only one program using this Macro. any help would be greatly appreciated. It does the printing, and posting, but not saving.

Sub SavePayrollKeeper2024WithNewName()
Dim NewFN As Variant
PostToYTD
PostToSocialSecurityRegister
PostToPTORegister


' Copy Next Pay Period to a new workbook
ThisWorkbook.Sheets.Copy
NewFN = "D:\Payroll Keeper 2024\Earning Statements\ Pay Period" & " # " & Range("B6").Value & " - " & Format(Range("B7"), "mm-dd-yyyy") & ".xlsm"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbookMacroEnabled (it's this part that keeps showing up in yellow}
ActiveWorkbook.Close
End Sub
 
This is just the Time Sheet, but you well see where Pay Period number is located and where Pay Period Date is.


Bi-Weekly Time Sheet.xlsm
ABCDEFGHIJKL
1BI-WEEKLY TIME SHEET
2
3Date Hired01/06/2024Employee's Details
4Beginning12/15/2023Employee's Name Name 401K Percentage Rate10.00%
5Ending12/28/2023Social Security Number 000-00-0000 Medical Insurance50.00
6Pay Period1Date Of Birth Date of Birth Dental/Vision Insurance25.00
7Pay Date01/04/2024Base Pay/Rate9.92Total Time Employed001
8YearsMonthsDays
9
10Weekday DateOptionsTime InTime OutTime InTime OutWorked Hrs. Regular Hrs. Overtime Hrs. PTO Hrs.Sick Hrs. Vacation Hrs.
12Fri 12/15Regular7:00 AM11:00 AM12:00 PM4:00 PM8.008.00 
13Sat 12/16Regular7:00 AM11:00 AM12:00 PM4:00 PM8.008.00 
14Sun 12/17Off   
15Mon 12/18Regular7:00 AM11:00 AM12:00 PM4:00 PM8.008.00 
16Tue 12/19Regular7:00 AM11:00 AM12:00 PM4:00 PM8.008.00 
17Wed 12/20Off   
18Thu 12/21Regular7:00 AM11:00 AM12:00 PM4:00 PM8.008.00 
19Total Hrs.40.00    
20
21Fri 12/22Regular7:00 AM11:00 AM12:00 PM4:00 PM8.008.00 
22Sat 12/23Regular7:00 AM11:00 AM12:00 PM4:00 PM8.008.00 
23Sun 12/24Off   
24Mon 12/25Regular7:00 AM11:00 AM12:00 PM4:00 PM8.008.00 
25Tue 12/26Regular7:00 AM11:00 AM12:00 PM4:00 PM8.008.00 
26Wed 12/27Off   
27Thu 12/28Regular7:00 AM11:00 AM12:00 PM4:00 PM8.008.00 
28Total Hrs.40.00    
29
30
31    
32
33Worked Hrs.Regular Hrs.Overtime Hrs.PTO Hrs. Sick Hrs.Vacation Hrs.
34Total Bi-Weekly Hrs.80.0080.00    
35
36Base Pay/Rate:9.9214.889.929.929.92
37Earnings:793.60    
38
39Total Bi-Weekly Earnings:$ 793.60
40
41
42
43
Time Sheet
Cell Formulas
RangeFormula
L4L4=IF(B4="","",VLOOKUP(G4,Settings!H1:I8,2,0))
L5L5=IF(B4="","",VLOOKUP(G5,Settings!H1:I8,2,0))
L6L6=IF(B4="","",VLOOKUP(G6,Settings!H1:I8,2,0))
B5B5=IF(B4="","",B4+13)
B6B6=IF(B4="","",INDEX(Settings!A2:A28,MATCH(B7,Settings!D2:D28,0)))
B7B7=IF(B4="","",B4+20)
E4E4=IF(B4="","",VLOOKUP(C4,Settings!H1:I8,2,0))
E5E5=IF(B4="","",VLOOKUP(C5,Settings!H1:I8,2,0))
E6E6=IF(B4="","",VLOOKUP(C6,Settings!H1:I8,2,0))
E7E7=IF(B4="","",VLOOKUP(C7,Settings!H1:I8,2,0))
J7J7=IF(B3="","",DATEDIF(B3,TODAY(),"Y"))
K7K7=IF(B3="","",DATEDIF(B3,TODAY(),"YM"))
L7L7=IF(B3="","",DATEDIF(B3,TODAY(),"MD"))
G12:G18,G21:G27G12=ROUND(IF((OR(C12="",D12="")),0,IF((D12<C12),((D12-C12)*24)+24,(D12-C12)*24))+IF((OR(E12="",F12="")),0,IF((F12<E12),((F12-E12)*24)+24,(F12-E12)*24)),2)
H12:H18,H21:H27H12=G12-I12
I12I12=ROUND(MAX(IF($V$6,MAX(0,SUM(H11:H$11)+G12-$V$7),0),IF($V$3,IF(G12>$V$4,G12-$V$4,0),0)),2)
I13:I18I13=ROUND(MAX(IF($V$6,MAX(0,SUM(H$11:H12)+G13-$V$7),0),IF($V$3,IF(G13>$V$4,G13-$V$4,0),0)),2)
A12A12=IF($B$4="","",$B$4)
A13A13=IF($B$4="","",$B$4+1)
A14A14=IF($B$4="","",$B$4+2)
A15A15=IF($B$4="","",$B$4+3)
A16A16=IF($B$4="","",$B$4+4)
A17A17=IF($B$4="","",$B$4+5)
A18A18=IF($B$4="","",$B$4+6)
H19:L19,H28:L28H19=SUM(H12:H18)
I21:I27I21=ROUND(MAX(IF($V$6,MAX(0,SUM(H$20:H20)+G21-$V$7),0),IF($V$3,IF(G21>$V$4,G21-$V$4,0),0)),2)
A21A21=IF($B$4="","",$B$4+7)
A22A22=IF($B$4="","",$B$4+8)
A23A23=IF($B$4="","",$B$4+9)
A24A24=IF($B$4="","",$B$4+10)
A25A25=IF($B$4="","",$B$4+11)
A26A26=IF($B$4="","",$B$4+12)
A27A27=IF($B$4="","",$B$4+13)
I31:L31I31=SUM(I28,I19)
G34G34=SUM(G12:G27)
H34:L34H34=SUM(H28,H19)
H36H36=IF(B4="","",E7)
I36I36=IF(B4="","",ROUND(1.5*H36,2))
J36J36=IF(B4="","",E7)
K36K36=IF(B4="","",E7)
L36L36=IF(B4="","",E7)
H37:L37H37=IF($B$4="","",ROUND(H36*H34,2))
K39K39=IF(B4="","",SUM(H37:L37))
Cells with Data Validation
CellAllowCriteria
B4List=Settings!$B$2:$B$28
B12:B18List=Settings!$F$2:$F$7
B21:B27List=Settings!$F$2:$F$7
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Give this a try:
Do not assume the folder address you have currrently is correct.
Go to the folder in explorer, select the folder and then right click the folder then select copy as path, paste it into the New Folder line in the code

Rich (BB code):
Sub SavePayrollKeeper2024WithNewName()
    Dim NewFN As Variant
    PostToYTD
    PostToSocialSecurityRegister
    PostToPTORegister
    
    ' Copy Next Pay Period to a new workbook
    Dim wbThis As Workbook
    Dim wsThis As Worksheet
    Dim NewFldr As String
    
    Set wbThis = ThisWorkbook
    Set wsThis = wbThis.Worksheets("Time Sheet")
    NewFldr = "D:\Payroll Keeper 2024\Earning Statements\"                  ' <--- Copy in the Address from Explorer
    
    If Right(NewFldr, 1) <> Application.PathSeparator Then NewFldr = NewFldr & Application.PathSeparator
    
    With wsThis
        NewFN = NewFldr & "Pay Period" & " # " & .Range("B6").Value & " - " & Format(.Range("B7"), "mm-dd-yyyy") & ".xlsm"
    End With
    
    wbThis.Sheets.Copy
    ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbookMacroEnabled
    ActiveWorkbook.Close
End Sub
 
Upvote 0
Solution
Give this a try:
Do not assume the folder address you have currrently is correct.
Go to the folder in explorer, select the folder and then right click the folder then select copy as path, paste it into the New Folder line in the code

Rich (BB code):
Sub SavePayrollKeeper2024WithNewName()
    Dim NewFN As Variant
    PostToYTD
    PostToSocialSecurityRegister
    PostToPTORegister
   
    ' Copy Next Pay Period to a new workbook
    Dim wbThis As Workbook
    Dim wsThis As Worksheet
    Dim NewFldr As String
   
    Set wbThis = ThisWorkbook
    Set wsThis = wbThis.Worksheets("Time Sheet")
    NewFldr = "D:\Payroll Keeper 2024\Earning Statements\"                  ' <--- Copy in the Address from Explorer
   
    If Right(NewFldr, 1) <> Application.PathSeparator Then NewFldr = NewFldr & Application.PathSeparator
   
    With wsThis
        NewFN = NewFldr & "Pay Period" & " # " & .Range("B6").Value & " - " & Format(.Range("B7"), "mm-dd-yyyy") & ".xlsm"
    End With
   
    wbThis.Sheets.Copy
    ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbookMacroEnabled
    ActiveWorkbook.Close
End Sub
That works Beautifully thanks so much for the help.
 
Upvote 0
That works Beautifully thanks so much for the help.
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0
Now, could someone kindly point out how @Alex Blakenburg macro differs from most of the earlier suggested macros (I mean, contents, not syntax).
The discussion uncovered that there were 2 separate issues:
• Folder Name incorrect
• File Name incorrect
Having a copy of the file was unlikely to help in resolving the Folder Name issue.

The code I posted:
• Isolated the folder name to make it conducive to pasting in the folder name by-passing historical versions and typing errors.
Inlcluded covering off a possible point of failure by checking for and if needed adding the path separator.
• The file name was using an unqualified Range reference and was being put together after the workbook sheets were being copied and the new workbook became the active workbook.
The copy process changes the active sheet to be the 1st sheet in the workbook (unless the active sheet was already the 1st sheet)
In the code , moved the construction of the file name to be before the copy process as well as being explicit in terms of referencing the workbook & worksheet. The XL2BB also gave the sheet name so the code didn't need to rely on the active sheet.
 
Upvote 0
Thanks @Alex Blakenburg, your macro is the best way to tackle the subject of the thread(y)but I'm sure that the conclusive was:
• Isolated the folder name to make it conducive to pasting in the folder name by-passing historical versions and typing errors.
 
Upvote 0

Forum statistics

Threads
1,215,161
Messages
6,123,375
Members
449,098
Latest member
Jabe

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top