Hi I've been on another thread where I asked if it was possible for a user to run a macro that asks them to select a file on the hd to open. I was given the below code. It works well for selecting/opening another file, but what I would really love for it to do would be to assign the file name (just filename.xls) to a variable. From there, I need to use said variable in a vlookup to search between two files. How would this be made possible?
Thanks!!
Sub Select_a_File() Dim wb As Workbook ' Prompt user to select a file With Application.FileDialog(msoFileDialogOpen) .InitialFileName = ThisWorkbook.Path ' Default path .FilterIndex = 3 .Title = "Please Select a File" .ButtonName = "Open" .AllowMultiSelect = False .Show If .SelectedItems.Count = 0 Then Exit Sub ' User clicked cancel Set wb = Workbooks.Open(Filename:=.SelectedItems(1)) End With End Sub</PRE>
Thanks!!
Sub Select_a_File() Dim wb As Workbook ' Prompt user to select a file With Application.FileDialog(msoFileDialogOpen) .InitialFileName = ThisWorkbook.Path ' Default path .FilterIndex = 3 .Title = "Please Select a File" .ButtonName = "Open" .AllowMultiSelect = False .Show If .SelectedItems.Count = 0 Then Exit Sub ' User clicked cancel Set wb = Workbooks.Open(Filename:=.SelectedItems(1)) End With End Sub</PRE>