How to hide source document?

P

Peter KNAP

Hi.
I am trying to create form for submission of applications where all used
forms are in one document in separate sections. After user open template of
this document macro asks him through UserForms what kind of application is he
asking for. Then he is asked to fill in the appropriate boxes in UserForms
and at the end only filed section is shown. Problem for me is that with
filled form also template document stays open.
I tried to write macro for closing source template document:

ActiveDcument.Close

but since template is actually active document last part of my macro:

Dim i As Long
i = 5
Dim source As Document, target As Document
Set source = ActiveDocument
Set target = Documents.Add
target.Range.FormattedText = source.Sections(i).Range.FormattedText

did not work because active document was no longer open then.

How could I solve this problem? I want user to see just UserForms and at the
end just part of the document he will print.
 
D

Doug Robbins - Word MVP

I would do that by having nothing in the original template and have a series
of templates for each of the possible forms and have the code in the user
form create a new document from the applicable template depending upon what
application the user is completing.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

Peter KNAP

OK but since I am not VBA programmer I do not know how to do it. ïŒ
I can not clearly imagine what do you think it should work like (
techniccaly I am not able to write the code)
So let me tell I have five different forms, some formfiled ase the same
(like name of applicant, name of active substance,...) but other are
completely new for every form.
If user click Form template AutoNew macro show UserForm1 where all five
possible kinds of forms will be displayed through OptionButtons.
Select one and code will lead him through all formfields.
Here ends my knowledge.
How to tell in what template are needed formfields which belongs to
appropriate textboxes? And I do not understand how does your proposal solve
my problem with open template?
Although user open empty template (for running the Macro) and only
applicable template will be used, this empty template stays open after
completing all steps of filling userforms.
Regards
Peter KNAP


„Doug Robbins - Word MVP" napísal (napísala):
 
B

Bear

Peter:

Word's intended operation is that a template (DOT file) is used as the basis
to create a new document (DOC file). The template is attached to the
resulting document.

Whenever you open a DOC file, Word attempts to open the attached DOT file.
The template opens invisibly (to the user). When the user closes the
document, Word also closes the template (if it's not Normal, and no other
document has it open).

If you create a template (an acutal DOT file, not a DOC file you renamed),
the code you put in the AutoNew macro executes every time your user creates a
new document based on that template. Code you put in the AutoOpen macro runs
every time the templat opens -- which is every time the new document opens.

So you should not be having any problems with your template remaining open.
The template (if I understand your plan) will contain all five sections, and
so will a new document based on that template. Your template will also
contain the userform that queries the user and gathers the required data, and
that deletes unused sections of the new document, and fills in the gathered
data.

When the user closes the new document, Word will also close the template.

Bear
 

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