Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ExApp.Workbooks.Open not working

Status
Not open for further replies.

damrus

Technical User
Jun 22, 2008
24
0
0
PL
hi,
Why does this code work in Excel 2000 and doesn't work in Excel 2007? VBA shows runtime error '1004' at line:
Set Wb = ExApp.Workbooks.Open(nextfile, 0)

Sub h()
directory = ThisWorkbook.Path & "\"
Dim ExApp As Excel.Application
Dim Wb As Workbook
Dim nextfile As String
Dim myfile As String
myfile = "szkod*.xls"
nextfile = VBA.Dir(directory & myfile)

Do Until Len(nextfile) = 0

Set ExApp = New Excel.Application
'Set Wb = ExApp.Workbooks.Open(.FoundFiles(x))
Set Wb = ExApp.Workbooks.Open(nextfile, 0)
Debug.Print (nextfile)
Wb.Close False

Set Wb = Nothing
Set ExApp = Nothing
nextfile = VBA.Dir()
Loop
End Sub
 




Hi,

Why are you assigning a new application object and opening the workbook in that instance? Way too much unnecessary stuff...
Code:
Do Until Len(nextfile) = 0
        
    Set Wb = Workbooks.Open(nextfile, 0)
    Debug.Print (nextfile)
    Wb.Close False
    
    nextfile = VBA.Dir()
Loop
Set Wb = Nothing


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
ok, but still the same problem. I can't open any file.
 



The modified code works for me in BOTH 2003 & 2007, opening workbooks in the target folder.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 



Are you running from a MACRO ENABLE WORKBOOK? Big difference in 2007!!!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top