ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   1004 Error on Workbooks.Open when run from inside IE (https://www.excelbanter.com/excel-programming/411285-1004-error-workbooks-open-when-run-inside-ie.html)

DS

1004 Error on Workbooks.Open when run from inside IE
 
Morning all, and happy Wednesday.

Have a slightly bizarre one to ask you fine people about.

The following Workbooks.Open statement forms part of my code.

Workbooks.Open Filename:=TargetPath & TargetBook, Password:="xxx",
WriteResPassword:="xxxx"

where TargetPath & TargetBook are defined previously.

Now, when running this from within Excel itself, it works fine and opens the
desired workbook.
When running from within IE, I get a 1004 ("Method 'Open' of Object
'Workbooks' Failed") - but only when running as part of the full macro. If I
hit debug, it takes me to that line, and hitting F8 to re-run that line in a
fit of frustration sees it work perfectly, and open the required workbook.

Me no understand. Please save what remains of my hair and tell me why this
is happening, and, more importantly, how the *flipping heck* to stop it!!

thanks in advance,

Norman Jones[_2_]

1004 Error on Workbooks.Open when run from inside IE
 
Hi Ds,

Without seeing the preceding code, I would
suggest that you try replacing

Workbooks.Open ...


with something like:

xlApp. Workbooks.Open ...



---
Regards.
Norman


"DS" wrote in message
...
Morning all, and happy Wednesday.

Have a slightly bizarre one to ask you fine people about.

The following Workbooks.Open statement forms part of my code.

Workbooks.Open Filename:=TargetPath & TargetBook, Password:="xxx",
WriteResPassword:="xxxx"

where TargetPath & TargetBook are defined previously.

Now, when running this from within Excel itself, it works fine and opens
the
desired workbook.
When running from within IE, I get a 1004 ("Method 'Open' of Object
'Workbooks' Failed") - but only when running as part of the full macro. If
I
hit debug, it takes me to that line, and hitting F8 to re-run that line in
a
fit of frustration sees it work perfectly, and open the required workbook.

Me no understand. Please save what remains of my hair and tell me why this
is happening, and, more importantly, how the *flipping heck* to stop it!!

thanks in advance,



Norman Jones[_2_]

1004 Error on Workbooks.Open when run from inside IE
 
Hi DS,

Correcting a typo, perhaps, also remove
the argument names:

xlApp.Workbooks.Open TargetPath & TargetBook, , , "xxx", "xxxx"



---
Regards.
Norman

"Norman Jones" wrote in message
...
Hi Ds,

Without seeing the preceding code, I would
suggest that you try replacing

Workbooks.Open ...


with something like:

xlApp. Workbooks.Open ...



---
Regards.
Norman



DS

1004 Error on Workbooks.Open when run from inside IE
 
Hi Norman,

Thanks for your suggestion, unfortunately, preceding with an "xlapp." just
gives me an "Object Required" error.

The code prior to the workbooks.open statement simply defines the TargetPath
and TargetBook - as I said, these work fine from run within Excel, and ok
when stepping through the code when opened in IE, so it doesn't appear to be
these which is causing the problem. For the sake of completion, though, the
full code concerned (edited) is:

TargetPath = "\\server1\shared\Level1\Level2\Level3\DataTables\ "
If Range("Sheet1!C2") = "HeaderRequired" Then
TargetBook = "Table1.xls"
Else
TargetBook = "Table2.xls"
End If

Workbooks.Open Filename:=TargetPath & TargetBook, Password:="xxx",
WritePassword:="xxxx"

DS

1004 Error on Workbooks.Open when run from inside IE
 
And the corrected (without argument names) version also just delivers a 424
Object Required both in Excel and IE...

Appreciate the help - even though we seem to be going backwards here!!!

"Norman Jones" wrote:

Hi DS,

Correcting a typo, perhaps, also remove
the argument names:

xlApp.Workbooks.Open TargetPath & TargetBook, , , "xxx", "xxxx"



---
Regards.
Norman

"Norman Jones" wrote in message
...
Hi Ds,

Without seeing the preceding code, I would
suggest that you try replacing

Workbooks.Open ...


with something like:

xlApp. Workbooks.Open ...



---
Regards.
Norman




Norman Jones[_2_]

1004 Error on Workbooks.Open when run from inside IE
 

Hi DS,

Have you tried replacing the named arguments
with position values, as in my later response?


---
Regards.
Norman

"DS" wrote in message
...
Hi Norman,

Thanks for your suggestion, unfortunately, preceding with an "xlapp." just
gives me an "Object Required" error.

The code prior to the workbooks.open statement simply defines the
TargetPath
and TargetBook - as I said, these work fine from run within Excel, and ok
when stepping through the code when opened in IE, so it doesn't appear to
be
these which is causing the problem. For the sake of completion, though,
the
full code concerned (edited) is:

TargetPath = "\\server1\shared\Level1\Level2\Level3\DataTables\ "
If Range("Sheet1!C2") = "HeaderRequired" Then
TargetBook = "Table1.xls"
Else
TargetBook = "Table2.xls"
End If

Workbooks.Open Filename:=TargetPath & TargetBook, Password:="xxx",
WritePassword:="xxxx"



DS

1004 Error on Workbooks.Open when run from inside IE
 
Hi Norman,

Yep, I had, was getting a 424 due to my own stupidity. I just replaced the
"Workbooks.Open..." with "xlapp.workbooks.open..." - without defining xlapp
and creating the Object. Evidently not enough coffee yet.

I've now done so, and the workbook is opening.

Thanks for your help, much appreciated!

"Norman Jones" wrote:


Hi DS,

Have you tried replacing the named arguments
with position values, as in my later response?


---
Regards.
Norman

"DS" wrote in message
...
Hi Norman,

Thanks for your suggestion, unfortunately, preceding with an "xlapp." just
gives me an "Object Required" error.

The code prior to the workbooks.open statement simply defines the
TargetPath
and TargetBook - as I said, these work fine from run within Excel, and ok
when stepping through the code when opened in IE, so it doesn't appear to
be
these which is causing the problem. For the sake of completion, though,
the
full code concerned (edited) is:

TargetPath = "\\server1\shared\Level1\Level2\Level3\DataTables\ "
If Range("Sheet1!C2") = "HeaderRequired" Then
TargetBook = "Table1.xls"
Else
TargetBook = "Table2.xls"
End If

Workbooks.Open Filename:=TargetPath & TargetBook, Password:="xxx",
WritePassword:="xxxx"




All times are GMT +1. The time now is 10:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com