+ Reply to Thread
Results 1 to 11 of 11

Invalid procedure call or argument error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Invalid procedure call or argument error

    thanks Kenneth. Unfortunately I do not know how to do this. If you could assist me further, that would be really appreciated.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Invalid procedure call or argument error

    'Code the open workbooks:
    Sub test()
      Dim wbk As Workbook, sFileName As String, sPath As String
      Dim i As Long, v() As Variant
      
      sPath = "C:\Users\M\Desktop\Test\"
      sFileName = sPath & "*.xlsx"
      
      'Make a varaint array of filenames.
      v() = GetFileList(sFileName)
      
      For i = LBound(v) To UBound(v)
        'Debug.Print v(i)
        Set wbk = Workbooks.Open(sPath & v(i))
        Test_File_Exist_With_Dir_v1
        Copy_To_Worksheets
        wbk.Close True
      Next i
    End Sub
    
    Function GetFileList(FileSpec As String) As Variant
    '   Returns an array of filenames that match FileSpec
    '   If no matching files are found, it returns False
    
        Dim FileArray() As Variant
        Dim FileCount As Integer
        Dim FileName As String
        
        On Error GoTo NoFilesFound
    
        FileCount = 0
        FileName = Dir(FileSpec)
        If FileName = "" Then GoTo NoFilesFound
        
    '   Loop until no more matching files are found
        Do While FileName <> ""
            FileCount = FileCount + 1
            ReDim Preserve FileArray(1 To FileCount)
            FileArray(FileCount) = FileName
            FileName = Dir()
        Loop
        GetFileList = FileArray
        Exit Function
    
    '   Error handler
    NoFilesFound:
        GetFileList = False
    End Function

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Run-time error '5' - Invalid procedure call or argument
    By datutt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-14-2015, 12:12 PM
  2. Run Time Error 5 Invalid Procedure Call or Argument
    By esong_98 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-28-2015, 03:31 PM
  3. Run-time error '5' Invalid procedure call or argument
    By CCSlice in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-07-2015, 03:21 AM
  4. Invalid procedure call or argument (Error 5)
    By vop2311 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-08-2014, 07:27 PM
  5. Runtime Error 5: Invalid procedure call or argument
    By Arasi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-07-2009, 11:49 AM
  6. Invalid procedure call or argument error
    By Patrick Simonds in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2006, 06:45 PM
  7. Run Time Error 5 - Invalid Procedure Call or Argument Q
    By John in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-26-2005, 05:05 PM

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