LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Opening a ReadOnly file in Excel VBA

It didn't work because you put the argument(s) in parentheses.

"Help" isn't much help on this issue, but...

(1) All methods are really functions, and return a value.

(2) In VBA you can choose to ignore the return value of a function, i.e. treat it as a Sub.

(3) If you are treating the method as a function and you want to capture the returned value in a
variable, you would use the parentheses, just as you would when calling any other function, i.e.

Set WB = Workbooks.Open(FileName:=.....,IgnoreReadOnlyRecom mended:=True)

(4) If you don't care about the return value, i.e. you are treating this as a Sub and you don't
have that leading "Set WB = ", then you must NOT use parentheses.

(5) If you ignore point #4 and use the parentheses without the "Set WB =", they tell VB to pass
the argument "ByCopy", i.e. create a copy of the argument and pass that copy by reference. The
purpose is to mimic a ByVal argument. If you do that, you have to put each argument inside its
own set of parentheses.

(6) You didn't get into trouble with the 1st statement, "Application.Workbooks.Open
(JobListPath)", because you supplied only one argument and you didn't use the named argument
syntax.

In summary, the rules are

1. If you are calling a VBA Sub (or a treating a Method as a Sub), you use parentheses around
the arguments ONLY if you use the Call keyword, i.e. Call Workbooks.Open(.....). If you write it
without using Call, you don't use parens.

2. If you are calling a Function, you must put the arguments in parens.




On Thu, 7 Aug 2003 04:22:01 -0700, "Demon" wrote:

excellent that worked - strange that my version did not
work considering it was the same args but a different
format! i shall remember that!

thanks v.much :o)


-----Original Message-----


Try this:

Application.Workbooks.Open _
Filename:=JobListPath, IgnoreReadOnlyRecommended:=True

Shunt
.




 
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
opening a file in Excel starts application but dose not open file Bob Shelton Excel Discussion (Misc queries) 1 July 2nd 08 07:51 PM
Excel thinks a file is ReadOnly but it is not. How to fix? Don Berman Excel Discussion (Misc queries) 1 March 27th 08 05:42 PM
Changing file from readonly Niall Excel Discussion (Misc queries) 2 July 27th 06 04:58 PM
opening an excel file opens a duplicate file of the same file skm Excel Discussion (Misc queries) 1 December 7th 05 05:52 PM
How do I use VC++6.0 to protect a excel file to readonly gowinder Excel Worksheet Functions 1 September 22nd 05 02:16 AM


All times are GMT +1. The time now is 04:18 PM.

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

About Us

"It's about Microsoft Excel"