Загрузка...

Excel VBA (part4): VBA File Dialog Box Saves File Name with Naming Conventions

In the video I demonstrate the steps on how to create a VBA procedure to save file with naming conventions on it's name according to the inputs given by users.

In the file we have applied VBA FileDialog Object with it's SaveAs DialogType argument. The FileDialog properties AllowMultiSelect,FilterIndex,InitialFileName,InitialViewand methods Show and Execute are utilized in the procedure.
The relevant explainations links of the Object and Propertites are list here for your refrences:
FileDialog object (Office) | Microsoft Docs: https://docs.microsoft.com/en-us/office/vba/api/office.filedialog

FileDialog.AllowMultiSelect property (Office) | Microsoft Docs: https://docs.microsoft.com/en-us/office/vba/api/office.filedialog.allowmultiselect

FileDialog.FilterIndex property (Office) | Microsoft Docs:
https://docs.microsoft.com/en-us/office/vba/api/office.filedialog.filterindex

FileDialog.InitialView property (Office) | Microsoft Docs:
https://docs.microsoft.com/en-us/office/vba/api/office.filedialog.initialview

FileDialog.Show method (Office) | Microsoft Docs:
https://docs.microsoft.com/en-us/office/vba/api/office.filedialog.show

FileDialog.Execute method (Office) | Microsoft Docs
https://docs.microsoft.com/en-us/office/vba/api/office.filedialog.execute

FileDialog.SelectedItems property (Office) | Microsoft Docs:
https://docs.microsoft.com/en-us/office/vba/api/office.filedialog.selecteditems

You may copy VBA codelines here or find the VBA codes from my blog site:
https://mikeyu.lovestoblog.com/projects/

VBA Procedure:

Sub CmdSaveFile_Click()
Dim strFolder, Filename As String
'select the front pgae tab
Sheets("Front Page").Activate
'get the region name
Filename = ActiveSheet.Cells(10, 7)
'get the account name
Filename = Filename & "_" & ActiveSheet.Cells(11, 7)

'get the contact name
Filename = Filename & "_" & ActiveSheet.Cells(19, 7)
'get Sales rep name
Filename = Filename & "_" & ActiveSheet.Cells(20, 7)
'Add time stamp and file extenstion
Filename = Filename & "_" & Format(Now(), "yyyy-mm-dd_hh_mm") & ".xlsm"

'Open SaveAs dialog to a default with default file name
With Application.FileDialog(msoFileDialogSaveAs)
.AllowMultiSelect = False '
.FilterIndex = 2 '2 is xlsm
.InitialFileName = ActiveSheet.Cells(15, 7) & Filename
.InitialView = msoFileDialogViewDetails

If .Show = -1 Then strFolder = .SelectedItems(1) Else Exit Sub
.Execute
End With
End Sub
For more info of my BI & Analytics, please refer to the following website links:

My BI & Analytics Website:
https://sites.google.com/view/mikeguangyuanyu/blog-pages/bi-analytics-and-automations

My blog website :
https://mikeyubianalytics.blogspot.com/

Видео Excel VBA (part4): VBA File Dialog Box Saves File Name with Naming Conventions канала Mike YU (BI&Analytics)
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки

На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.

Об использовании CookiesПринять