Solved

Accessing of Macros in word...Tricky one?

Posted on 2006-06-28
23
206 Views
Last Modified: 2010-04-07
Ok the title is a little deceptive but I'm sure the solution is macro related. A small firm has asked me to have a look at this issue. #
Using a new doc managment system, every time they create a blank document through this system the document is already saved and named and added to the system, ok , fine. So when they go to use a template it creates a new document (not created from within the doc managment system) and thus when saved does not show up in the doc manager console.

Is there anyway that when you open a template it will transfer to the blank document originally opened.
At the moment the user goes to file-New-->(Templates) On My Computer-->chooses a template a new document opens. So is there anyway I can get this template to open in the already saved and named blank document that is open.

Does that make any sense!!!Sorry...any help would be greatly appreciated.

jh
0
Comment
Question by:thomaskilroy
  • 9
  • 5
  • 5
  • +1
23 Comments
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
Comment Utility

you could include a macro in the templates, that find an existing word app,
and paste all contents of the template in it.

but you _have_ to do some checks, to see if the user has not got 3 or more instances of word running
0
 
LVL 3

Expert Comment

by:gafoorgk
Comment Utility
yes, u can attach a template to an already open and saved document by using the following command

ActiveDocument.AttachedTemplate = "C:\<template name>.dot"

your question is not very clear to tell u where exactly u should insert this code.
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
It is hard to match your description to what Word does.

Usually a user does not 'Open' a template. A developer is more lilkey to do that. The template is used to create a new document, and it will be the document's Attached Template. Many times the template will be the Normal template.

You can change the attached template via the Word User interface (Tools/Templates and Add-ins) or programatically as
gafoorgk suggests. You would then be able to use the new template's styles, macros, custom toolbars, etc. But if the template had some document text, hopefully nicely formatted, then that would not appear. It would have to be copied to the new document.

It sounds as if what you want any new document to be forced to take up the name of the pre-existing 'New' document that your document management system has already assigned. It might just be possible to do that, provided that there is a programmatic way of finding out whether such a blank document exists and what its name is.

However, it sounds like a fairly predictable conundrum, and one that the designers of the system would have considered, so they may have a ready answer. Perhaps their literature and/or support should be consulted.
0
 

Author Comment

by:thomaskilroy
Comment Utility
Guys thanks alot for your help I appreciate it, ok. Sorry for not explaining myself properly (Mark_FreeSoftware  seems to be closest to what I'm looking for).

The software is a legal case management package. At the moment all this firms precedents are in template form in word but I wish to include all created documents in the new package. So what I would wish to happen is:
1. Uses chooses blank document from within software package, this opens a blank word document ( letterNo13.doc) which is automatically saved to the system. Now my users are accustomed to going to file-->new and choosing a precedent template, but obviously this opens a new document.

What I was wondering is when they choose this template is it possible for its contents to be placed in the already saved blank document opened from the case management software.

I understand that this seems very convoluted and any suggestions of achieving this by other means would be greatly appreciated, its just that the majority of people using this system are not very computer 'savvy' and the old way is the best way...thanks again guys

Mark how might I code this ?
0
 

Author Comment

by:thomaskilroy
Comment Utility
Hello!!? can anyone help me with this..........
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
Comment Utility

>>What I was wondering is when they choose this template is it possible for its contents to be placed in the already saved blank document opened from the case >>management software.

you could edit the default template,

and you can also have a document execute a macro when it is opened (even for new documents)

which one do you want more info about?

(and pls give me a hint of your knowledge of word/macro's so i know to what level of detail to explain to
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 250 total points
Comment Utility
The simplest thing to do would be to save the new document with the document name of the one created by your document management system.

Option Explicit

Private Sub Document_New()
    ActiveDocument.SaveAs "C:\MyFolder\letter13.doc"
End Sub

Whatever we do, we need to know the name of the blank document from the document management system. Is there a rule for that?
0
 

Author Comment

by:thomaskilroy
Comment Utility
AAAAAAHHHHHH I just spent an hour writing a reply and it was lost I've never been more frustrated with this sh*T f**k.........
0
 

Author Comment

by:thomaskilroy
Comment Utility
ok...thanks for the reply guys...ggggrrrrrrr..........I appreciate it. Mark my experience is very limited so I'm not sure what the best option is just to go over it.


Here again is the scenario:
1. User opens word from within Case Management software, they are requested to give the doc a name, which is saved automatically.
2. Now there are 60 templates on this users computer so user now wants to use one of these 60 templates.

How would the user be able to access any one of these templates and have it's contents place in the already saved and open, blank document referred to in Step 1 above?
It is too impractical to have 10 different toolbars etc. so I am unsure of how to do this?

Graham,cheers for your time,
 I don't think that will work because everytime a document is generated from a template, the user will be asked would they like to replace the existing document. I know this will confuse our older users. It adds a layer of complexity I want to avoid.

Thanks Guys.

0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
Comment Utility

can't they just open a template, and then save it somewhere, instead first saving somewhere and than opening the template?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
VBA .SaveAs shouldn't prompt to overwrite. The difficulty is in finding the document that the Case Management software has just created. How do the users find it again? Can we do that programatically?
0
 

Author Comment

by:thomaskilroy
Comment Utility
Great guys thanks for your help

The folder scheme is based on client number and case numbers, so saving files to these folders is far from intuitive,it would be very hard to find the correct client and then the correct case folder.

""can't they just open a template, and then save it somewhere, instead first saving somewhere and than opening the template?""
Alas no, to be honest if they could this would be a mute question. Unfortunately, this is the chain of events that must occur."

""The difficulty is in finding the document that the Case Management software has just created. How do the users find it again?""
The users will find the documents by finding the correct case in the Case Management system, the files pertaining to the specific case will be listed. The idea is to keep the user out of the file tree structure on the application server.

Thanks again guys.........
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
Surely the application will allow the user to choose the template at the initial creation time.
This one seems to:

http://www.casemanagerpro.com/features_documents.asp
0
 

Author Comment

by:thomaskilroy
Comment Utility
Thanks for the prompt reply Graham,
THe application does allow this, but this company does not want all its templates coded within the case management system. Instead they wish to be able to choose them from within word. If this could be done another way I would do it! Unfortunately this is the preferred way for this company.

Any ideas?
0
 

Author Comment

by:thomaskilroy
Comment Utility
Going back to your original post MArk:

""you could include a macro in the templates, that find an existing word app,
and paste all contents of the template in it.""


How might this be done?

Thanks.
0
 

Author Comment

by:thomaskilroy
Comment Utility
Hi Guys,
I think I may of found a ridiculously easy way around this issue. By going to 'Insert File' in the Insert menu of Word. So I think I'm closer to the solution. Guys, is there a macro that would run when you try to open a template it would replicate insert file and place the contents in a new document?
Thanks again for your time.
0
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 250 total points
Comment Utility

you can create a macro that runs when a document is open.

to do so, open a new document

press alt + f8

type a name in the field, and press Create (or somthing like that, i'm not on an english word, so it could be a little different)
let's assume you used this name : "TemplateRunMacro" (without the quotes ofcourse)


now the editor will pop up
expand the item Normal (or whichever the name is of the template to attach to)
expand Microsoft Word -objects
doubleclick on "ThisDocument"

now paste this code:

Private Sub Document_Open()
  call TemplateRunMacro
End Sub



if you save it, the sub TemplateRunMacro will be executed every time a document is opened

0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
Will there only be one 'template' to load from?

If so, the only problem would be to make sure that it only happens once. This could be avoided by setting a document variable.

Note that this code would have to be in the document that is being opened.

Private Sub Document_Open()
    Dim v As Variable
    Dim rng As Range
   
    For Each v In ThisDocument.Variables
        If v.Name = "TemplateLoaded" Then
            Exit Sub
        End If
    Next v
    Set rng = ThisDocument.Range
    rng.InsertFile "C:\MyFolder\MyTemplate.doc"
    ThisDocument.Variables.Add "TemplateLoaded"
End Sub



0
 

Author Comment

by:thomaskilroy
Comment Utility
Thanks guys, I really appreciate it. I will try it Monday morning....have a great weekend
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
Comment Utility

recommendation:

split between GrahamSkan (300 pts)
and me (200 pts)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now