Runtime error '1004'

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I am not sure why this code does not worked because I used a similar variation in another project and it worked. I checked the file location of the file and path needing to be opened and its correct. Not sure why its not finding the workbook. The error occurs on the
Code:
Set wb = Workbooks.Open(sFile)
Here's the rest of the code. Thank you.
Code:
Option Explicit


'Declares variable names
Dim sPath As String, sFile As String
Dim wb As Workbook
Dim ws As Worksheet


Private Sub Workbook_Open()
    
    'Declares variable names
    Dim ans As String
    Dim ansSplit As String
    Dim i As Integer
    
    sPath = "C:\Users\Desktop\Bulk_Yield_Report\"
    
    sFile = sPath & "F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004.xls"
    
    Set wb = Workbooks.Open(sFile)
    
    
    ans = MsgBox("Is this a split Lot?", vbQuestion + vbYesNo, "Split Lot")
    
    If ans = vbNo Then
        frmPackageYield.Show vbModeless
    Else
        ansSplit = InputBox("How many times does this lot split?", "Split Lot")
        For i = 1 To ansSplit
            frmPackageYield.Show 'vbModeless
        Next i
        'NEEDS CODING HERE
    End If
        
    Call ClearContents
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
when you step through and before set wb. what is held in the sfile string
 
Upvote 0
I set up a watch and and put sPath and sFile to see what the value would be and the code below came from the watch for the expression "sFile". Thank you for your quick response.
Code:
"C:\Users\Desktop\Bulk_Yield_Report\F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004.xls"
 
Upvote 0
Ok, I figured it out. When I was sent the file from my supervisor, he put the file location and name of the file in an email, along with the file attachment. So I copied and pasted the file name and location and created a location on my desktop to simulate a server location. Anyway, he accidentally forgot the last letter x in the file extension. So instead of name being "F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004.xls", it is actually "F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004.xlsx". One hour gone. Thank you.
 
Upvote 0
lots still using 2003. so it didn't look wrong
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top