I need a macro for the following task.
1. ask for the file name through inputbox
2. open the file if the name is correct otherwise give an error msgbox.
3. the directory can be specified initially in the vba.
Thanks.
I need a macro for the following task.
1. ask for the file name through inputbox
2. open the file if the name is correct otherwise give an error msgbox.
3. the directory can be specified initially in the vba.
Thanks.
Hi
Rather asking for the filename, let the user select the file.
Code:Sub kTest() Dim strFile As String With Application.FileDialog(msoFileDialogFilePicker) .AllowMultiSelect = False .Title = "Select the file.." .InitialFileName = "D:\" 'adjust the default folder .Filters.Clear .Filters.Add "Excel Files", "*.xls*" If .Show = -1 Then strFile = .SelectedItems(1) Else MsgBox "No file selected", vbInformation, "ExcelFox.com" Exit Sub End If Workbooks.Open strFile, 0 End With End Sub
Cheers !
Excel Range to BBCode Table
Use Social Networking Tools If You Like the Answers !
Message to Cross Posters
@ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)
It worked perfectly. Thanks admin
Bookmarks