locked
InputBox vs MsgBox RRS feed

  • Question

  • I want to use one or the other to prompt  the user for a file name to open.

    Is there a preference?

     

    Wednesday, August 24, 2011 6:19 PM

Answers

  • I don't know why do you think abot a msgbox to prompt something, but I should answer no to both the alternatives. InputBox is too much old and you have to control too much bad eventual results.

    You can use FileDialog.


    please, mark this as answer if it is THE answer
    ----------------
    Diego Cattaruzza
    Microsoft MVP - Visual Basic: Development
    blog: http://community.visual-basic.it/Diego
    web site: http://www.visual-basic.it
    • Proposed as answer by danishani Sunday, March 4, 2012 11:06 PM
    • Marked as answer by danishani Thursday, March 8, 2012 6:25 AM
    Wednesday, August 24, 2011 6:46 PM
  • hi,
     
    why not a FileDialog(msoFileDialogFilePicker) ?
     
    Sub test()
    Dim Wk As Workbook, FD As FileDialog
    ChDir "c:\"
    Set FD = Application.FileDialog(msoFileDialogFilePicker)
    FD.AllowMultiSelect = False 'allow selection just one file
    FD.Filters.Clear 'remove the filters
    FD.Filters.Add Description:="Excel Files", Extensions:="*.xls;*.xlsx" 'filtrer sur les fichiers excel
    FD.Show 'display the dialog box
    If FD.Show = -1 Then
      Set Wk = Application.Workbooks.Open(fileName:=FD.SelectedItems(1))
      MsgBox Wk.Name & "now is open"
    Else
      Exit Sub 'the user pressed Cancel
    End If
    Set FD = Nothing
    End Sub
     --
    isabelle
     
    Le 2011-08-24 14:19, Harv1e a écrit :
    > I want to use one or the other to prompt the user for a file name to open.
    >
    > Is there a preference?
    >
     
    • Proposed as answer by danishani Sunday, March 4, 2012 11:06 PM
    • Marked as answer by danishani Thursday, March 8, 2012 6:25 AM
    Friday, August 26, 2011 11:51 AM

All replies

  • I don't know why do you think abot a msgbox to prompt something, but I should answer no to both the alternatives. InputBox is too much old and you have to control too much bad eventual results.

    You can use FileDialog.


    please, mark this as answer if it is THE answer
    ----------------
    Diego Cattaruzza
    Microsoft MVP - Visual Basic: Development
    blog: http://community.visual-basic.it/Diego
    web site: http://www.visual-basic.it
    • Proposed as answer by danishani Sunday, March 4, 2012 11:06 PM
    • Marked as answer by danishani Thursday, March 8, 2012 6:25 AM
    Wednesday, August 24, 2011 6:46 PM
  • MsgBox and InputBox are not alternatives. The clue is in the name: a MsgBox is for Messages, an InputBox for Input.
     
    That said, you may well want something else altogether, depending on what you actually want to do, and in what application you are doing it.
     
     

    Enjoy,
    Tony
    www.WordArticles.com
    Friday, August 26, 2011 9:47 AM
  • hi,
     
    why not a FileDialog(msoFileDialogFilePicker) ?
     
    Sub test()
    Dim Wk As Workbook, FD As FileDialog
    ChDir "c:\"
    Set FD = Application.FileDialog(msoFileDialogFilePicker)
    FD.AllowMultiSelect = False 'allow selection just one file
    FD.Filters.Clear 'remove the filters
    FD.Filters.Add Description:="Excel Files", Extensions:="*.xls;*.xlsx" 'filtrer sur les fichiers excel
    FD.Show 'display the dialog box
    If FD.Show = -1 Then
      Set Wk = Application.Workbooks.Open(fileName:=FD.SelectedItems(1))
      MsgBox Wk.Name & "now is open"
    Else
      Exit Sub 'the user pressed Cancel
    End If
    Set FD = Nothing
    End Sub
     --
    isabelle
     
    Le 2011-08-24 14:19, Harv1e a écrit :
    > I want to use one or the other to prompt the user for a file name to open.
    >
    > Is there a preference?
    >
     
    • Proposed as answer by danishani Sunday, March 4, 2012 11:06 PM
    • Marked as answer by danishani Thursday, March 8, 2012 6:25 AM
    Friday, August 26, 2011 11:51 AM