Quick Macro Help

Jar888

Board Regular
Joined
Jan 15, 2022
Messages
61
Office Version
  1. 2016
Platform
  1. Windows
Hi all. Running currently the below macro;

Sub PRODTRACKSummary_Button1_Click()
Application.ScreenUpdating = False
Dim PS As String
Dim SavePath As Variant
Dim FileName As String

Val2 = Format(Range("D1").Value, "ddmmyyyy")


PS = Left(ActiveSheet.Name, 4)
SavePath = "F:\Data\2579\13 Progress Reporting Programming\03 Daily Diary\Lateral Development\Current Month\Prodtrack Summary"
ActiveSheet.Copy
ActiveWorkbook.SaveAs FileName:= _
SavePath & "\" & Val2 & " " & "ProdTrak Summary" & ".xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
Application.ScreenUpdating = True
End Sub

I want to change the masterdate after each save, but the addition was crashing my VBA macros.

Range("D1") = Range("D1") + 1

Can anyone help me with this? Also, how would I add a pop up to confirm data input prior to executing the save function?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Maybe something like this.

VBA Code:
Sub PRODTRACKSummary_Button1_Click()
    Dim SavePath As String, FileName As String
    Dim WS As Worksheet
    Dim MasterDate As Date
    
    Application.ScreenUpdating = False
    Set WS = ActiveSheet
    
    MasterDate = WS.Range("D1").Value
    FileName = Format(MasterDate, "ddmmyyyy") & " " & "ProdTrak Summary.xlsx"
    SavePath = "F:\Data\2579\13 Progress Reporting Programming\03 Daily Diary\Lateral Development\Current Month\Prodtrack Summary"
    SavePath = SavePath & "\" & FileName
    
    Select Case MsgBox("Master Date: " & WS.Range("D1").Value & vbCrLf & vbCrLf _
            & "File Name: " & FileName & vbCrLf & vbCrLf _
            & "SavePath: " & SavePath & vbCrLf & vbCrLf _
            & "Continue?", vbYesNo Or vbQuestion, Application.Name)
        Case vbYes
            ActiveSheet.Copy
            ActiveWorkbook.SaveAs FileName:=SavePath, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
            ActiveWorkbook.Close False
            WS.Range("D1").Value = MasterDate + 1 'increment date
    End Select
    Application.ScreenUpdating = True
End Sub
End Sub
 
Upvote 0
Solution
Thanks mate! Your a life saver. I changed the wording in the pop up but otherwise she looks like she works every time and increments the date.
 
Upvote 0
Got a follow up question,

is there a way to add to the code to automatically accept this pop up;
1644710165856.png
 
Upvote 0
Use Application.DisplayAlerts. Example:

VBA Code:
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:=SavePath, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    Application.DisplayAlerts = True
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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