+ Reply to Thread
Results 1 to 3 of 3

Could not open excel file using VBA

  1. #1
    Registered User
    Join Date
    06-11-2021
    Location
    Vietnam
    MS-Off Ver
    MS Office 365 Pro
    Posts
    5

    Could not open excel file using VBA

    I tried to open the workbook using VBA but failed and got the "Run-time error 1004"

    "Sorry we couldn't find C:\Users\smile\Desktop\UIpath\hoc them\BaiTap\output\Password.xlsx. Is it possible it was removed, renamed or delete?"

    I have checked but the file is still there in the folder and it is not opened. I have also tried Dir but still not working. Please help. Thank you.

    My code as follows:

    Please Login or Register  to view this content.
    Last edited by smiledt06; 09-19-2021 at 08:02 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: Could not open excel file using VBA

    That error message is very specific. The only way you will get that message if the file in the message really does not exist.
    I have checked but the file is still there
    How did you check?

    I suggest you copy the file path that is shown in the message (just the folder part, not including the file name), then go to Windows File Explorer and paste in the path to what happens. If you are not able to copy text from the error message then put the following line in your code

    Please Login or Register  to view this content.
    and copy the output from the Immediate window
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Could not open excel file using VBA


    Quote Originally Posted by smiledt06 View Post
    I have also tried Dir but still not working.
    So obviously it's just a bad file path !

    PHP Code: 
    Sub CheckMacro5()
      Const 
    "Control"
        
    Dim F$, V
            F 
    ThisWorkbook.Path "\output\Password.xlsx"
        
    If Dir(F) > "" Then
            MsgBox 
    "File exists …", , T
        
    Else
            
    Application.GetOpenFilename("Excel files,*.xlsx")
            
    MsgBox "Original file :  " vbLf vbLf "Selected file :  " V48T
        End 
    If
    End Sub 
    Last edited by Marc L; 09-20-2021 at 04:26 AM.

+ 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. Replies: 5
    Last Post: 12-23-2022, 04:02 AM
  2. Replies: 5
    Last Post: 02-01-2018, 10:56 AM
  3. Replies: 2
    Last Post: 12-21-2015, 04:20 PM
  4. A file iis found if I open Excel FIRST, but not if I open the file by double-clicking
    By Ed_Collins in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2013, 01:52 AM
  5. [SOLVED] open variably named file, copy/paste data into consolidation file, open next file in list
    By sllawrence1968 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 09:49 PM
  6. VBA for excel 2003. Open file dialog box, open 2007 file xlsx, continue with code
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2011, 12:12 AM
  7. Replies: 1
    Last Post: 08-05-2006, 04:59 PM

Tags for this Thread

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