Hi guys i working on a project that open an excel document using vb6 but i encounter this.

Run-time error 1004 :

C:\aaaaa\aaaa\myBook1.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct.

This is the Code:

Private Sub Form_Click()
Dim xlApp As Excel.Application
Set xlApp = New Excel.Application

xlApp.Workbooks.Open (App.Path & "\myBook1.xls")
xlApp.Visible = True
End Sub

tell what is wrong with my code... thanks in advance

Not much to go on here. There appears to be nothing wrong with your code per se. I can assume that you have already included the Excel Object Library in your project references (otherwise, you wouldn't have even got this error message).

Try, just as a science experiment, to hard-code the location of the spreadsheet, rather than using App.Path. If that works, then there is a problem with using App.Path. That could be because the spreadsheet you're trying to open isn't in the same directory as the application .EXE file. If you're having this problem in the development environment, use debug.print in your code to display the value of App.Path in the "Immediate" window. That might give you a clue. If you have not saved the VB Project, then App.Path will give you the location of the VB.EXE file. Once you save the VB Project, then App.Path will give you the project directory.

Hope this helps. Good luck!

Not much to go on here. There appears to be nothing wrong with your code per se. I can assume that you have already included the Excel Object Library in your project references (otherwise, you wouldn't have even got this error message).

Try, just as a science experiment, to hard-code the location of the spreadsheet, rather than using App.Path. If that works, then there is a problem with using App.Path. That could be because the spreadsheet you're trying to open isn't in the same directory as the application .EXE file. If you're having this problem in the development environment, use debug.print in your code to display the value of App.Path in the "Immediate" window. That might give you a clue. If you have not saved the VB Project, then App.Path will give you the location of the VB.EXE file. Once you save the VB Project, then App.Path will give you the project directory.

Hope this helps. Good luck!

like this i change the path and make it complete but no such change happen still same error i get. But thanks for ur reply sir

Dim xlApp As Excel.Application
Set xlApp = New Excel.Application

xlApp.Workbooks.Open ("C:\Users\HP Pavilion dv6\Desktop\Practice\Book1.xls")
xlApp.Visible = True

Ow i got working now it seems a write the wrong File extension (.xls) it should be (.xlsx) sorry for my dumbness Thanks!

Hi i created a code in vba. the requirements is that
-input is 3 color bands from a resistor(in order)
-and the output of the resistor in ohms
-make function work for 3 colors.I am using vba. I came up with a code but it has my function highlighted in yellow. whats wrong with it?
'Resistor By: Diamond Wongus
Function Resistor(color1, color2, color3)

'I cannot put the equation until the end
Select Case color1
Case "black", "Black"
color1 = 0
Case "brown", "Brown"
color1 = 1
Case "Red", "red"
color1 = 2
Case "Orange", "orange"
color1 = 3
Case "Yellow", "yellow"
color1 = 4
Case "Green", "green"
color1 = 5
Case "Blue", "blue"
color1 = 6
Case "Violet", "violet", "Purple", "purple"
color1 = 7
Case "Grey", "grey", "Gray", "gray"
color1 = 8
Case "White", "white"
color1 = 9
Case "Gold", "gold"
color1 = 0.1
Case "Silver""silver"
color1 0.001
'the above information is for color 1
Select Case color2
Case "black", "Black"

color2 = 0
Case "brown", "Brown"
color2 = 1
Case "Red", "red"
color2 = 2
Case "Orange", "orange"
color2 = 3
Case "Yellow", "yellow"
color2 = 4
Case "Green", "green"
color2 = 5
Case "Blue", "blue"
color2 = 6
Case "Violet", "violet", "Purple", "purple"
color2 = 7
Case "Grey", "grey", "Gray", "gray"
color2 = 8
Case "White", "white"
color2 = 9
Case "Gold", "gold"
color2 = 0.1
Case "Silver""silver"
color2 0.001
'the above data is color 2
Select Case color3

Case "black", "Black"
color3 = 0
Case "brown", "Brown"
color3 = 1
Case "Red", "red"
color3 = 2
Case "Orange", "orange"
color3 = 3
Case "Yellow", "yellow"
color3 = 4
Case "Green", "green"
color3 = 5
Case "Blue", "blue"
color3 = 6
Case "Violet", "violet", "Purple", "purple"
color3 = 7
Case "Grey", "grey", "Gray", "gray"
color3 = 8
Case "White", "white"
color3 = 9
Case "Gold", "gold"
color1 = 0.1
Case "Silver""silver"
color3 0.001
'The above data is color 3
End Select
Resistor = (color1 * 10 + color2) * (10 ^ color3)


End Function

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.