p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

vba_word thread: A Typical and sensitive Problem


Message #1 by bveerendrakumar@y... on Thu, 20 Jun 2002 15:49:39
I haven't gone through your problem in full but if you want to find out 
how many Word documents are open, you can use the Document nad or 
Documents object or else if you want to know how many instances of word 
are open use FindWindow API.

Prakash

> Hai friends,
 > 
 >        Here i m facing a typical problem.Here my problem is ,user 
creates 
a>  form and he saves it.After that he links that document to my 
v> bapplication.When he links it i want to give a password to that file 
and 
f> rom then he must open his linked documents with my vbapplication 
o> nly.Even if he opens from the location he should not have the provision 
t> o modify the document.Here I wrote some code to do that like following

>   dim myapp as word.application
 >  dim mydoc as word.document
p> rivate sub protdoc(byval myfile as string)
d> im obj as object
s> et myapp=new word.application

> ' This code is to find wether the document is in taks list, if it exists 
i> n the task list imeediately i wouldbe closed.If it is in task list and 
if 
i>  don't close it, i m getting my document read only.

> for each obj in myapp.tasks
 >       if instr(ucase(obj.name),ucase(myfile))>0 then
 >             myapp.tasks.item(obj.task).close
 >        end if
n> ext obj

> 'this is the code i wrote to protect the document

>       set mydoc=myapp.documents.open(mypath&myfile)
 >      mydoc.protech wdallowonlycomments,"mypass"
 >      mydoc.save
 >      mydoc.close wdsavechanges
e> nd sub

> 'And to break it i wrote the followin code

> private sub brkprotdoc(byval myfile as string)
d> im obj as object
s> et myapp=new word.application

> ' This code is to find wether the document is in taks list, if it exists 
i> n the task list imeediately i wouldbe closed.If it is in task list and 
if 
i>  don't close it, i m getting my document read only.

> for each obj in myapp.tasks
 >       if instr(ucase(obj.name),ucase(myfile))>0 then
 >             myapp.tasks.item(obj.task).close
 >        end if
n> ext obj

>       set mydoc=myapp.documents.open(mypath&myfile)
 >      mydoc.unprotect"mypass"
 >      mydoc.save
 >      mydoc.close wdsavechanges

> for each obj in myapp.tasks
 >       if instr(ucase(obj.name),ucase(myfile))>0 then
 >             myapp.tasks.item(obj.task).windowstate=2
 >              exit for
 >        end if
n> ext obj
e> nd sub

> this is my code

> but my problem is when i m closing the my vbapplication i need to check 
h> ow many word docs have been openend and i need to protect them again 
when 
i> t is being closed.If the docs are still working then my application 
s> hould not allow user to close my vbapplication.

> Please give me a soon reply.It is very much needed to me to continue my 
p> roject.

> Thanking you in advance

> B.Veerendra Kumar

>     

  Return to Index