Excel VBA to save file to a defined location and defined name.

minmark

New Member
Joined
Jul 18, 2016
Messages
44
Dear Gents,

my code as following
Dim MyFile As String


MyFile = ActiveWorkbook.Name
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="D:\E-DRIVE2\1234567\Logbook\2016\" & MyFile

End sub

my current file name is "LogBook July"
My question are:
1) I would like to save this file name as LogBook +"month name" like "LogBook Aug", "LogBook Nov". How do i make this happen?

2) I want to make a inputbox to input the year to replace the save location "2016" and let the file save to 2017 folder if the year is over 2017.


I try to use formula like =month(today()) ... but can't figure out.:confused::(

Hope anybody can help me.

Thanks.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi Mark

to get the short month just concatenate the following

Format(Month(Date), "mmm")

you can also use concatenation to automatically input the current year.

Year(Date)

Therefore try

Code:
[COLOR=#333333]MyFile = ActiveWorkbook.Name & " " & [/COLOR]Format(Month(Date), "mmm")
[COLOR=#333333]Application.DisplayAlerts = False[/COLOR]
[COLOR=#333333]ActiveWorkbook.SaveAs Filename:="D:\E-DRIVE2\1234567\Logbook\" & Year(Date) & "\" & MyFile
[/COLOR]

I hope this helps


Regards

Dave
 
Last edited:
Upvote 0
Hopefully, this may help as well.


Code:
Sub FILESAVE()


Dim dt As String, wbNam As String


    wbNam = "D:\Users\Documents\TEST_FILE_" 'FILE DIR PATH AND NAME
    dt = Format(CStr(Now), "MMM_YYYY") 'MONTH & YEAR
    ActiveWorkbook.Sheets.Copy 'CREATES COPY OF WORKBOOK IF WB IS MACRO-FREE OTHERWISE CAN IGNORE THIS LINE"
    ActiveWorkbook.SaveAs Filename:=wbNam & dt, FileFormat:=51 '51 = XLSX FORMAT; UPDATE FILE FORMAT AS PER REQUIREMENTS
    ActiveWorkbook.Close Savechanges = True
    
End Sub

:cool:
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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