Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 201
Default Run-time Error '5' - Invalid procedure call or argument


I am not sure what is going on here and am interested in any feedback I can
get please.

I am using some code to open an excel workbook that is password protected. I
also use code to save the file with the password.

On one particular file I am getting this run-time error in the following code:

DataFile = Application.GetOpenFilename("Data Collect Automation - Data
Files (*.DCA), *.DCA", , "Data Collect Automation - Data Files")
If DataFile < "" And DataFile < "False" Then
On Error Resume Next
Workbooks.Open DataFile, 0, False, , Password:="mypassword"
<--error
here

Two things have me beat, why does this not get trapped in the error trap?

Secondly, the file does get opened so the password must be correct, I tried
opening the same file the same way but without a password and I get an error
1004 and it gets trapped ok. So if the file gets opened as normal (although
the code crashes), what is the error actually referring to? It can't be the
code because it works fine on all the other files and has been working fine
for years.

I have an import routine routine so I imported all the data from the old
file to a new fiile, saved it and re-opened without any code change and it
works fine. So it must be related to this particualar file. I didn't want to
waste to much time finding out why it occured, but without an error trap to
handle it I am forced to fix one or the other.

Anyone?

--
Trefor
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Run-time Error '5' - Invalid procedure call or argument

Just a guess--maybe the .DCA file that you're opening has a workbook_open event
that has a problem. You could avoid that event (and all events) by turning off
..enableevents before you try to open the other workbook.

Second (and this is just a personal perference), I wouldn't mix positional
parameters with named parameters. I find code using named parms much easier to
use--especially when some parms are omitted.

And if you declare DataFile as a variant, you could just check to see if it was
false (not the string "False").

Dim DataFile As Variant
Dim wkbk As Workbook
DataFile = Application.GetOpenFilename _
(filefilter:="Data Collect Automation - Data Files, *.DCA", _
Title:="Data Collect Automation - Data Files")
If DataFile < False Then
Application.EnableEvents = False
On Error Resume Next
Set wkbk = Workbooks.Open(Filename:=DataFile, _
UpdateLinks:=0, ReadOnly:=False, Password:="mypassword")
On Error GoTo 0
Application.EnableEvents = True
End If

But this is more of a next test for you than a real suggestion.

Good luck.

Trefor wrote:

I am not sure what is going on here and am interested in any feedback I can
get please.

I am using some code to open an excel workbook that is password protected. I
also use code to save the file with the password.

On one particular file I am getting this run-time error in the following code:

DataFile = Application.GetOpenFilename("Data Collect Automation - Data
Files (*.DCA), *.DCA", , "Data Collect Automation - Data Files")
If DataFile < "" And DataFile < "False" Then
On Error Resume Next
Workbooks.Open DataFile, 0, False, , Password:="mypassword"
<--error
here

Two things have me beat, why does this not get trapped in the error trap?

Secondly, the file does get opened so the password must be correct, I tried
opening the same file the same way but without a password and I get an error
1004 and it gets trapped ok. So if the file gets opened as normal (although
the code crashes), what is the error actually referring to? It can't be the
code because it works fine on all the other files and has been working fine
for years.

I have an import routine routine so I imported all the data from the old
file to a new fiile, saved it and re-opened without any code change and it
works fine. So it must be related to this particualar file. I didn't want to
waste to much time finding out why it occured, but without an error trap to
handle it I am forced to fix one or the other.

Anyone?

--
Trefor


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 201
Default Run-time Error '5' - Invalid procedure call or argument

Dave,

I wish I could guess as good as you ;). Spot on and I will implement your
suggestions. MAny thanks.

--
Trefor


"Dave Peterson" wrote:

Just a guess--maybe the .DCA file that you're opening has a workbook_open event
that has a problem. You could avoid that event (and all events) by turning off
..enableevents before you try to open the other workbook.

Second (and this is just a personal perference), I wouldn't mix positional
parameters with named parameters. I find code using named parms much easier to
use--especially when some parms are omitted.

And if you declare DataFile as a variant, you could just check to see if it was
false (not the string "False").

Dim DataFile As Variant
Dim wkbk As Workbook
DataFile = Application.GetOpenFilename _
(filefilter:="Data Collect Automation - Data Files, *.DCA", _
Title:="Data Collect Automation - Data Files")
If DataFile < False Then
Application.EnableEvents = False
On Error Resume Next
Set wkbk = Workbooks.Open(Filename:=DataFile, _
UpdateLinks:=0, ReadOnly:=False, Password:="mypassword")
On Error GoTo 0
Application.EnableEvents = True
End If

But this is more of a next test for you than a real suggestion.

Good luck.

Trefor wrote:

I am not sure what is going on here and am interested in any feedback I can
get please.

I am using some code to open an excel workbook that is password protected. I
also use code to save the file with the password.

On one particular file I am getting this run-time error in the following code:

DataFile = Application.GetOpenFilename("Data Collect Automation - Data
Files (*.DCA), *.DCA", , "Data Collect Automation - Data Files")
If DataFile < "" And DataFile < "False" Then
On Error Resume Next
Workbooks.Open DataFile, 0, False, , Password:="mypassword"
<--error
here

Two things have me beat, why does this not get trapped in the error trap?

Secondly, the file does get opened so the password must be correct, I tried
opening the same file the same way but without a password and I get an error
1004 and it gets trapped ok. So if the file gets opened as normal (although
the code crashes), what is the error actually referring to? It can't be the
code because it works fine on all the other files and has been working fine
for years.

I have an import routine routine so I imported all the data from the old
file to a new fiile, saved it and re-opened without any code change and it
works fine. So it must be related to this particualar file. I didn't want to
waste to much time finding out why it occured, but without an error trap to
handle it I am forced to fix one or the other.

Anyone?

--
Trefor


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
to call procedure in a worksheet in a module CAPTGNVR Excel Discussion (Misc queries) 4 January 30th 07 09:39 PM
Compile Error Argument Not optional [email protected] Excel Discussion (Misc queries) 1 August 16th 06 04:58 PM
Run-time error '5': Invalid Procedure Call or Argument Nikila Excel Discussion (Misc queries) 2 February 24th 06 09:26 PM
simplify procedure to get rid of 0 error values in a spreadsheet Frederic Excel Worksheet Functions 1 February 8th 06 04:47 AM
VBA Compile error: Procedure too large? Jerry Dyben Excel Discussion (Misc queries) 1 October 31st 05 10:15 PM


All times are GMT +1. The time now is 01:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"