View Single Post
 
Old 12-20-2011, 11:09 PM
Catalin.B Catalin.B is offline Windows Vista Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

Press alt+F11 to open Visual Basic Editor, on the left side, you will see VBA Project(your file name.xlsx), right click on it, insert new module, then on the right side of the window, paste the codes below.
Activate macro: Excel 2007-2010: press Microsoft Office Button , then click Excel Options. In Trust Center category, click on Trust Center Settings, then click on category Macro Settings.(recomended option- Medium).This way, excel will ask for your permission to activate macro for that file.
As you can see , there are two macros, one will open all file types, the second will open only excel files. Macros:
Code:
Option Explicit
Sub search()
Dim vFile As Variant, MyPath As String
MyPath = ThisWorkbook.Path 'replace with your desired path
CreateObject("WScript.Shell").CurrentDirectory = MyPath
       ChDir MyPath
       'for all files type
       vFile = Application.GetOpenFilename()
End Sub

Sub search2()
Dim vFile As Variant, MyPath As String
MyPath = "\\Flory\D\" 'replace with your desired path
CreateObject("WScript.Shell").CurrentDirectory = MyPath
       ChDir MyPath
'for excel files only
       vFile = Application.GetOpenFilename("Excel Files (*.xl*)," & _
      "*.xl*", 1, "Select Excel File", "Open", False)
End Sub
Reply With Quote