+ Reply to Thread
Results 1 to 5 of 5

Small problem with GetopenFileName

  1. #1
    Peter Rooney
    Guest

    Small problem with GetopenFileName

    Good morning all!

    I want to be able to let the user select multiple files from a
    GetOpenFileName dialog box, but also filter the file list to Excel files only
    and trap for the user pressing Escapel.

    If I use:

    SAPDataWorkbook = Application.GetOpenFilename()
    If SAPDataWorkbook = False Then
    Exit Sub
    End If
    Workbooks.Open Filename:=SAPDataWorkbook

    I can press escape OK AND open a workbook

    If however I change the first line thus:

    SAPDataWorkbook = Application.GetOpenFilename( _
    filefilter:="Excel Files (*.xls),*.xls", MultiSelect:=True)
    If SAPDataWorkbook = False Then
    Exit Sub
    End If
    Workbooks.Open Filename:=SAPDataWorkbook

    to filter to *.xls I can press escape, but get the message "Type mismatch"
    with

    If SAPDataWorkbook = False Then

    highlighted.

    Can anyone out there help, please?

    Thanks in advance

    Pete


  2. #2
    NickHK
    Guest

    Re: Small problem with GetopenFileName

    I assume you have
    Dim SAPDataWorkbook As String

    If you read the help you will see "If MultiSelect is True, the return value
    is an array of the selected file names (even if only one filename is
    selected). "
    Hence change it to: Dim SAPDataWorkbook As Variant

    NickHK

    "Peter Rooney" <[email protected]> wrote in message
    news:[email protected]...
    > Good morning all!
    >
    > I want to be able to let the user select multiple files from a
    > GetOpenFileName dialog box, but also filter the file list to Excel files

    only
    > and trap for the user pressing Escapel.
    >
    > If I use:
    >
    > SAPDataWorkbook = Application.GetOpenFilename()
    > If SAPDataWorkbook = False Then
    > Exit Sub
    > End If
    > Workbooks.Open Filename:=SAPDataWorkbook
    >
    > I can press escape OK AND open a workbook
    >
    > If however I change the first line thus:
    >
    > SAPDataWorkbook = Application.GetOpenFilename( _
    > filefilter:="Excel Files (*.xls),*.xls", MultiSelect:=True)
    > If SAPDataWorkbook = False Then
    > Exit Sub
    > End If
    > Workbooks.Open Filename:=SAPDataWorkbook
    >
    > to filter to *.xls I can press escape, but get the message "Type mismatch"
    > with
    >
    > If SAPDataWorkbook = False Then
    >
    > highlighted.
    >
    > Can anyone out there help, please?
    >
    > Thanks in advance
    >
    > Pete
    >




  3. #3
    Peter Rooney
    Guest

    Re: Small problem with GetopenFileName

    Hi, Nick,

    No, I thought of that - it's declared as Variant already :-(

    Pete


    "NickHK" wrote:

    > I assume you have
    > Dim SAPDataWorkbook As String
    >
    > If you read the help you will see "If MultiSelect is True, the return value
    > is an array of the selected file names (even if only one filename is
    > selected). "
    > Hence change it to: Dim SAPDataWorkbook As Variant
    >
    > NickHK
    >
    > "Peter Rooney" <[email protected]> wrote in message
    > news:[email protected]...
    > > Good morning all!
    > >
    > > I want to be able to let the user select multiple files from a
    > > GetOpenFileName dialog box, but also filter the file list to Excel files

    > only
    > > and trap for the user pressing Escapel.
    > >
    > > If I use:
    > >
    > > SAPDataWorkbook = Application.GetOpenFilename()
    > > If SAPDataWorkbook = False Then
    > > Exit Sub
    > > End If
    > > Workbooks.Open Filename:=SAPDataWorkbook
    > >
    > > I can press escape OK AND open a workbook
    > >
    > > If however I change the first line thus:
    > >
    > > SAPDataWorkbook = Application.GetOpenFilename( _
    > > filefilter:="Excel Files (*.xls),*.xls", MultiSelect:=True)
    > > If SAPDataWorkbook = False Then
    > > Exit Sub
    > > End If
    > > Workbooks.Open Filename:=SAPDataWorkbook
    > >
    > > to filter to *.xls I can press escape, but get the message "Type mismatch"
    > > with
    > >
    > > If SAPDataWorkbook = False Then
    > >
    > > highlighted.
    > >
    > > Can anyone out there help, please?
    > >
    > > Thanks in advance
    > >
    > > Pete
    > >

    >
    >
    >


  4. #4
    Bob Phillips
    Guest

    Re: Small problem with GetopenFileName

    SAPDataWorkbook = Application.GetOpenFilename( _
    filefilter:="Excel Files (*.xls),*.xls", MultiSelect:=True)
    If Not IsArray(SAPDataWorkbook) Then
    MsgBox "Nothing selected"
    Else
    For i = LBound(SAPDataWorkbook) To UBound(SAPDataWorkbook)
    Workbooks.Open Filename:=SAPDataWorkbook(i)
    Next i
    End If


    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Peter Rooney" <[email protected]> wrote in message
    news:[email protected]...
    > Good morning all!
    >
    > I want to be able to let the user select multiple files from a
    > GetOpenFileName dialog box, but also filter the file list to Excel files

    only
    > and trap for the user pressing Escapel.
    >
    > If I use:
    >
    > SAPDataWorkbook = Application.GetOpenFilename()
    > If SAPDataWorkbook = False Then
    > Exit Sub
    > End If
    > Workbooks.Open Filename:=SAPDataWorkbook
    >
    > I can press escape OK AND open a workbook
    >
    > If however I change the first line thus:
    >
    > SAPDataWorkbook = Application.GetOpenFilename( _
    > filefilter:="Excel Files (*.xls),*.xls", MultiSelect:=True)
    > If SAPDataWorkbook = False Then
    > Exit Sub
    > End If
    > Workbooks.Open Filename:=SAPDataWorkbook
    >
    > to filter to *.xls I can press escape, but get the message "Type mismatch"
    > with
    >
    > If SAPDataWorkbook = False Then
    >
    > highlighted.
    >
    > Can anyone out there help, please?
    >
    > Thanks in advance
    >
    > Pete
    >




  5. #5
    Peter Rooney
    Guest

    Re: Small problem with GetopenFileName

    Thanks a lot Bob! :-)

    Pete


    "Bob Phillips" wrote:

    > SAPDataWorkbook = Application.GetOpenFilename( _
    > filefilter:="Excel Files (*.xls),*.xls", MultiSelect:=True)
    > If Not IsArray(SAPDataWorkbook) Then
    > MsgBox "Nothing selected"
    > Else
    > For i = LBound(SAPDataWorkbook) To UBound(SAPDataWorkbook)
    > Workbooks.Open Filename:=SAPDataWorkbook(i)
    > Next i
    > End If
    >
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (replace somewhere in email address with gmail if mailing direct)
    >
    > "Peter Rooney" <[email protected]> wrote in message
    > news:[email protected]...
    > > Good morning all!
    > >
    > > I want to be able to let the user select multiple files from a
    > > GetOpenFileName dialog box, but also filter the file list to Excel files

    > only
    > > and trap for the user pressing Escapel.
    > >
    > > If I use:
    > >
    > > SAPDataWorkbook = Application.GetOpenFilename()
    > > If SAPDataWorkbook = False Then
    > > Exit Sub
    > > End If
    > > Workbooks.Open Filename:=SAPDataWorkbook
    > >
    > > I can press escape OK AND open a workbook
    > >
    > > If however I change the first line thus:
    > >
    > > SAPDataWorkbook = Application.GetOpenFilename( _
    > > filefilter:="Excel Files (*.xls),*.xls", MultiSelect:=True)
    > > If SAPDataWorkbook = False Then
    > > Exit Sub
    > > End If
    > > Workbooks.Open Filename:=SAPDataWorkbook
    > >
    > > to filter to *.xls I can press escape, but get the message "Type mismatch"
    > > with
    > >
    > > If SAPDataWorkbook = False Then
    > >
    > > highlighted.
    > >
    > > Can anyone out there help, please?
    > >
    > > Thanks in advance
    > >
    > > Pete
    > >

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1