none
GetOpenFilname|FileFilter works in macro unless Macro is autoopen. RRS feed

  • Question

  •  ChosenFile = Application.GetOpenFilename(FileFilter:="CreditCardFiles (*.etx), *.etx", Title:="Please select a file")

    That is the first functional line of the macro.  If I run it from VBA, it works just fine.  It displays a list of files with the ETX extension, and it displays only those files, and the FileType selector says CreditCardFiles.

    However, if that macro runs automatically upon opening the spreadsheet, I instead get 

    and a list of standard Excel Files.

    Needless to say, I do not want to instruct my end users to go to the developer tab, hit Visual Basic, select the module... 

    A little help here please?

    Phil

    Tuesday, December 12, 2017 12:00 AM

All replies

  • Hello Phil,

    How do you let the macro run automatically upon opening the spreadsheet? 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 12, 2017 1:36 AM
    Moderator
  • The first few lines of my code:

    --------------------------------------------------------------------------------------------------------------

    Private Sub Workbook_Open()
    '
    '
     Dim NewFileName As String
     Dim lastrow As Integer
     
     ChosenFile = Application.GetOpenFilename(FileFilter:="CreditCardFiles (*.etx), *.etx", Title:="Please select a file")
    If ChosenFile = False Then
    ' They pressed Cancel
    MsgBox "Stopping because you did not select a file"
    Exit Sub
    Else
    Debug.Print ChosenFile
    Workbooks.Open FileName:=ChosenFile
    End If

    Tuesday, December 12, 2017 5:32 PM
  • Hello,

    I test the code above and it works fine. Could you reproduce the issue using other machines? I suggest you add a breakpoint at line Application.GetOpenFilename method, save the document and re-open, check if it would hit the breakpoint and then run step by step to see the open file dialog.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 13, 2017 1:51 AM
    Moderator