Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to get my Word document to close with the click of a button

Status
Not open for further replies.

Y2KCobra

IS-IT--Management
Mar 11, 2003
15
GB
Good Morning to all,

I feel goofey asking this question but I have tried for several days now to solve a simple issue. All I want to do is create a new document from template A and this document has a form in it to create a report. When Im ready to create a report I create a new document (from form) and populate bookmarks with my information. Then all I want to do is close down the form and close the original document, thus, leaving the new document in view.

Steps I use:

1) Create a new document based on a template

2) A form loades and I access a database to populate the dialog boxes

3) When I click generate report I create a new word document based on another template and then save it with a name and date.

4) [Problem] I then want to shut down the form and the document that displayed the form but when I try to get the name of the original document it just returns the template name arg

Ex: New doc is "document3" [I cannot get the name document3?] created from template "A". Form pops up and I create a report. Then when I try to close the form and automatically close the document it will now close. When I try "ThisDocument.name" command is displays the name of my template and not the document based on that template.

Macro code Im using =
"
Sub LoadForm()
Load StatusForm
StatusForm.Show 'vbModeless
ThisDocument.SaveAs ("H:\My Documents\SteveTesting\Temp.doc")
Documents("Temp.doc").Close wdDoNotSaveChanges
End Sub
"

Does anyone have an idea of what I am missing?

Thank you in advance,

Steve
 
I'm not sure why you are needing to close the form template? Generally, when you use a template properly (file-new), it creates a document, which is a copy of the template. Why would you need to save this other file? Why not just save the document that was created with the template?

Seems to me you are making a 3rd document for the report? Why? Why not just use DocumentX, which is already open?

Anne Troy
Way cool stuff:
 
Hey Anne,

Thank you for responding. The reason the original is not saved is because I do not want to store that document unless I could strip the forms and macros from it. The file will be too big to store daily. I would much rather store a 20K file then a 200K file. Do you have any thoughts oh how I could do this?

Steve
 
Hey Anne,

The template name is "business 6 12 03.dot". I placed it into the c:\programs\microsoft office\templates directory and then create a new document by going to file, new, and selecting that template. That document automatically opens up the form. When Im ready to publish my report I first write to a database (not doing yet but and accessing the database). Then I create a new report document by opening a document with bookmarks, save it under another name then want to shut down my form and 1st document. everything works perfect but the shut down.

Does this help?

Steve
 
Anne,

The second document has no macros or forms in it, only bookmarks. I searched earlier for vba code to strip forms and macros from a document and was unsuccessful. I got the system to work but would rather just use the one template to work and to be able to strip off forms and macros from the document before saving. I do appreciate your help and would like to know if you have any examples?

Steve
 
I would be interested in the template as well, if you could email it me. gerry.knight@hrdc-drhc.gc.ca

I am not quite getting your problem, and why you are doing it this way. Even if you (for whatever reason) are using a third file with bookmarks ( and why not write bookmarks as part of your form code, then insert your data) if , as Anne pointed out, you are loading from a temlate the template file itself is not opened.

Perhaps you should make a call to whatever documents are open and close them specifically with activedocument, rather than thisdocument.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top