Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jul 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, I am not sure why I get an error message when I run this program. The error message states it finds the file, but can't open it. My file is not read-only and the folder is shared. I am trying to open up all .xls files in a specified directory and eventually do some extra actions to the files I open.

    Error: "Run-time error '1004': 'A.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct."

    Sub Combine()
    MFile ("E:\tempdelete\")
    End Sub

    Function MFile(Path As String) As Long
    Dim strTemp As String
    Dim lngCount As Long
    Dim Filenm As String

    strTemp = Dir(Path & "*.xls")

    Do While strTemp <> ""
    lngCount = lngCount + 1
    strTemp = Dir
    Workbooks.Open (Dir(Path & "*.xls"))
    Loop

    'MFile = lngCount
    End Function

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    The login in your MFile function is slightly confused. Try this version:
    Code:
    Function MFile(Path As String) As Long
      Dim strTemp As String
      Dim lngCount As Long
    
      strTemp = Dir(Path & "*.xls")
      Do While Not strTemp = ""
    	lngCount = lngCount + 1
    	Workbooks.Open Path & strTemp
    	strTemp = Dir
      Loop
    
      MFile = lngCount
    End Function

  3. #3
    New Lounger
    Join Date
    Jul 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hans, your awesome. Thanks.

Posting Permissions

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