VBA Open

P

Peter Kinsman

I am trying to use VBA to open a protected worksheet. I know the password,
but in the the example of using VBA to Open a Workbook, the file name is the
only parameter shown. Does anyone know the syntax for the password please.

Many thanks

Peter Kinsman
 
P

Peter Kinsman

By a process of elimination, I have found that the syntax is:

Workbooks.Open filename, UpdateLinks:=0, Password:="password"

I haven't come across the := operator since it was called "becomes" when I
used Algol in the sixties but Word Basic and Excel Basic still insist on it,
because it refused to work with an equals sign.

Hope this might be of use to someone else in the future.

Peter
 
A

Andrew Cushen

Peter-

What you have come across is a Named Argument.

I quote from the VBA Help:

"named argument:

An argument that has a name that is predefined in the
object library. Instead of providing a value for each
argument in a specified order expected by the syntax, you
can use named arguments to assign values in any order. For
example, suppose a method accepts three arguments:

DoSomeThing namedarg1, namedarg2, namedarg3

By assigning values to named arguments, you can use the
following statement:

DoSomeThing namedarg3 := 4, namedarg2 := 5, namedarg1 := 20

Note that the named arguments don't have to appear in the
normal positional order in the syntax
"

I can see where you would be frustrated, as the VBA help
just says the parameter must be a string. However, if you
look at the error message, it says "= expected". If you
then hit F1 for Help, the Help file mentions Named
Arguments. Admittedly, it's the 3rd bullet point down, but
it IS there! ;-)

BTW, The UpdateLinks parameter is optional.

-Andrew
=======================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top