title: GetOpenFileName opens in background
body: <p>I have a macro that prompts the user to select a comma separated values file, however, whenever the macro runs, it opens the window behind all the other open windows. The macro is never called from excel, but only by other scripts. I've tried messing with <code>Application.DisplayAlerts</code> and <code>Application.ActiveWindow</code> but to no avail. Any suggestions are greatly appreciated.</p>
  
  <pre><code>Function folderselection()
      Dim fnameandpath As Variant
      Dim path As String
  
      Dim objshell As Object
      Set objshell = CreateObject("wscript.shell")
      objshell.AppActivate "excel"
  
      Application.DisplayAlerts = False
      path = ActiveWorkbook.path
      ChDrive (path)
      ChDir (path)
  
      Application.ActiveWindow.Visible = True
      Application.WindowState = xlMaximized
  
      fnameandpath = Application.GetOpenFilename(FileFilter:=("BOM CSV/RPT (*.CSV;*.RPT), *.CSV; *.RPT"), Title:="Select The BOM File To Copy Values From")
      Application.WindowState = xlMinimized
  
      If fnameandpath = False Then Exit Function
      Workbooks.Open Filename:=fnameandpath, ReadOnly:=True
  
      Application.DisplayAlerts = True
      folderselection = CStr(fnameandpath)
      ActiveWorkbook.Close
  End Function
  </code></pre>