>Hi Cetin,
>I wonder if you could help me. I've been doing quite a bit with Word and oword.documents.open(theDoc+'.doc') works fine for me. I wanted to add readonly to this, but I'm not sure how. I tried doing this: oword.documents.open filename:=theDoc+'.doc', readonly:=True but it doesn't like it. I also stored the value of theDoc+'.doc' to theDoc and tried ...filename:=&theDoc, readonly:=True but it doesn't like that either. I really need to be able to open a file as REadOnly and also, in another instance, have a password. I'd really appreciate hearing from you.
Hi Mary,
oword.documents.open filename:=theDoc+'.doc', readonly:=True
is "named arguments" style and could be used with macros or VB. Unfortunately VFP doen't support named arguments so you must use "positional arguments". It is like passing parameters to a function where parameters are in a specific order. That is if a word function is:
myWordFunc(Par1, Par2, Parn)
then calling :
myFunc("Hello",,3)
would be threated as Par1:="Hello", Par2 whatever is default, Par3 := 3.
When you look word VBA help for "Open" method you see :
Expression.Open(FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible)
VBA help (thanks it does now) gives the parameters in their expected order (IOW as "positional arguments"). Following it there is a description about what could "expression" be (Applies to). Then what parameters mean and if they're required or optional (for "open" only FileName is required, rest optional variant -> variable). In applies to list there is "Document" object too so it means you could use it with "oword.documents". We want to pass optional readonly and password :
oword.documents.open(theDoc+'.doc', ,.t., ,"myPassWord")
ConfirmConversions and AddToRecentFiles were optional so we just omitted them with preserving their parameter poisitions with commas. After PasswordDocument, rest of parameters are optional too and we closed parentheses there for we just want them to be at their default.
As a final note whenever you use open, save or alike in word (and other office apps.) I suggest you pass a complete path+filename including extension (c:\myPath\myFile.doc). Otherwise word uses its default file locations which generally is not the one you want.
Cetin