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

Mike YU (BI&Analytics)
Mike YU (BI&Analytics)
1.6 هزار بار بازدید - 21 ساعت پیش - In the video I demonstrate
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: docs.microsoft.com/en-us/office/vba/api/office.fil… FileDialog.AllowMultiSelect property (Office) | Microsoft Docs: docs.microsoft.com/en-us/office/vba/api/office.fil… FileDialog.FilterIndex property (Office) | Microsoft Docs: docs.microsoft.com/en-us/office/vba/api/office.fil… FileDialog.InitialView property (Office) | Microsoft Docs: docs.microsoft.com/en-us/office/vba/api/office.fil… FileDialog.Show method (Office) | Microsoft Docs: docs.microsoft.com/en-us/office/vba/api/office.fil… FileDialog.Execute method (Office) | Microsoft Docs docs.microsoft.com/en-us/office/vba/api/office.fil… FileDialog.SelectedItems property (Office) | Microsoft Docs: docs.microsoft.com/en-us/office/vba/api/office.fil… You may copy VBA codelines here or find the VBA codes from my blog site: 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: sites.google.com/view/mikeguangyuanyu/blog-pages/b… My blog website : mikeyubianalytics.blogspot.com/
21 ساعت پیش در تاریخ 1403/07/09 منتشر شده است.
1,600 بـار بازدید شده
... بیشتر