Next Invoice SaveAs date yyyymmdd and file name

ShaneMorr

New Member
Joined
Sep 28, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am new to the macro side of excel and have utilized the modules from an existing Mrexcel youtube video.

This is what i currently have and it works fine however i would like to add 2 more functions.

VBA Code:
Sub NextDelnote()
Range("H5").Value = Range("H5").Value + 1
Range("A21:A50").ClearContents
Range("H3:I3").ClearContents
Range("H8:H9").ClearContents
Range("H21:H50").ClearContents
End Sub

Sub SaveDelWithNewName()
Dim NewFN As Variant
' Copy Delivery note to a new workbook
ActiveSheet.Copy
NewFN = "C:\Users\name\Documents\ " & Range("H5").Value & Range("G3").Value & Range("H3").Value & ".xlsx"
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:="c:\Users\name\Documents\" & Range("H5").Value & Range("G3").Value & Range("H3").Value & ".pdf"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
NextDelnote
End Sub


1. I would like to save the file as follows. yyyymmdd_("H5"),("G3"),("H3"). How do i add the date to the saved file?
2. I have assigned buttons for the macros in the worksheet. Is it possible that the saved file no longer shows these buttons.

Any other improvements that could be made would be greatly appreciated.

Thanks in advance and look forward to the feedback.

Shane
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
VBA Code:
Option Explicit

Sub NextDelnote()
Range("H5").Value = Range("H5").Value + 1
Range("A21:A50").ClearContents
Range("H3:I3").ClearContents
Range("H8:H9").ClearContents
Range("H21:H50").ClearContents
End Sub

Sub SaveDelWithNewName()
Dim NewFN As Variant

With ActiveSheet
 .Shapes("Button 1").Visible = msoFalse
' Copy Delivery note to a new workbook
ActiveSheet.Copy
NewFN = "C:\Users\name\Documents\" & Format(Date, "yyyymmdd") & "_" & Range("H5").Value & Range("G3").Value & Range("H3").Value & ".xlsx"
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Users\name\Documents\" & Range("H5").Value & Range("G3").Value & Range("H3").Value & ".pdf"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
 .Shapes("Button 1").Visible = msoTrue
End With

NextDelnote
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,412
Members
448,960
Latest member
AKSMITH

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