Log in

View Full Version : deleting sections in document in VBA



associates
01-23-2008, 08:57 PM
Hi,

I was wondering if anyone might be able to help me here. My goal is to build a userform that give user freedom to choose which section in the document to delete. But i've already had troubled deleting the current section. Given if i leave the pointing cursor to where the section that i want to remove, how do i do that in word VBA ( i have read about people using the bookmarks - i don't quite understand this)? But also it has to take into account that whatever formatting the previous page has, it should not change.

What i mean by that is

I have a document set up as below
cover page
TOC
executive summary
section 1
section 2
...
bibliography
appendix

TOC, executive summary, sections, bibliography and appendix have different footer in terms of the formatting of the pagination.

TOC may have a footer with Page i
executive summary starts with Page ES1
sections starts with Page 1
bibliography starts with Page BI1
and so on

Coming back to deleting section issue. if the pointing cursor is in section 1, the section 1 is to be deleted. How do i preserve the formatting in the previous page which in this case, would be the executive summary that has different page number.

Thank you in advance

fumei
01-24-2008, 10:56 AM
It is not as easy as you may think. i am not quite following though.

You have the cursor in Section1 - is this the cover page?

"How do i preserve the formatting in the previous page which in this case"

How can you have a "previous page" to Section 1?

Try carefully spelling out exactly what you want to happen, and also tell us WHY you may need it to happen.

associates
01-24-2008, 05:12 PM
Hi Gerry,

Sorry if i have made a confusion here.

Ok, let me explain a bit of our motives here.
The aim here is to set up a standard document template that would enable our
staff to create a report for our company. At the moment, many reports are
different in terms of format. There are lots of inconsistencies throughout
all the reports made by different staff. So we thought, by having a proper
template made ready for staff to use, we could resolve this issue.

In the template (.dot), we plan on making lots of macros placed in the menu
that would enable user to do the job they desire. For example, we have macros
called "insert a section", "insert picture", "insert table", and so on. I
know these would override the features provided by word 03. But these macros
would shorten the steps needed for the staff to say "insert a section or sub
section" for example.

At the moment, i was creating a macro that would insert a bibliography into
the document. By clicking the button "insert bibliography", it would
automatically create a new section break and put the word "bibliography" as
the heading with appropriate header and footer. Of course, this will depend on the location of the insertion point of the cursor as the bibliography section will be created in the next page.

To answer your query,
No, Section 1 is not a cover page. It is a page after either the TOC or executive summary (depends on user).

So here is the flow of the report
at the start, we have
- cover page
- TOC
- executive summary (depends on user)
- Section 1
- Section 2
- ...
- Section n
- Bibliography (depends on user)
- Glossary (depends on user)

So, my question here is if the user is at Section 1 and wish to remove it. How does it work? But also it has to take into account that whatever formatting the previous page has, it should not change.

TOC, executive summary, sections, bibliography and Glossary have different footer in terms of the formatting of the pagination.

TOC may have a footer with Page i
executive summary starts with Page ES1
sections starts with Page 1
bibliography starts with Page BI1
and so on

Hope i spelled it out clearly this time. Otherwise, i'll try a different approach.

Thank you in advance

fumei
01-25-2008, 10:45 AM
"No, Section 1 is not a cover page. It is a page after either the TOC or executive summary (depends on user)."

OK, first off, you need to think in the terms that Word thinks. Your "Section 1" in the above quote is a typographical term, a content term.

In Word terms, what you state in the quote is impossible. Section 1 (as a Section) is always, always, always, the start of the document. You can not have anything before Section 1. Section 1 is...well, 1. The start.

So here is the flow of the report
at the start, we have
- cover page (this IS in Section 1)
- TOC
- executive summary (depends on user)
- Section 1
- Section 2

Now, how - exactly - are the changes/breaks between cover page, TOC, Exec Summary done? Are they Section Breaks? Are they PageBreaks?

It is absolutely critical to know these things.

As I mentioned, removing Sections - real, Word Sections - can be very tricky, and not as easy as you may think. Oh, removing them is easy, but the effect, the rsult, can be extremely messy and decidely non-intuitive.

Word moves Section information backwards. Simple example:

Section 1 - Header = "Yadda"
Section 2 - Header = "Blah"
Section 3 - Header = "Yo!"

If Section 2 is removed, there are now only two Sections. HOWEVER, the headers will be:

Section 1 - Header = "Yadda"
Section 2 - Header = "Yo!"

Backwards. Word will take the header from what was Section 3, and use it for the new Section 2.

I realize this can be very confusing It certainly is not very intuitive, but that is the way Word works.

What you seem to be wanting is possible, but it needs to be set up very carefully.

"So, my question here is if the user is at Section 1 and wish to remove it. How does it work? But also it has to take into account that whatever formatting the previous page has, it should not change."

It depends. It depends on whether it is a REAL section, a Word Section.

As for formatting, if you are going to do this kind of stuff, I would encourage you to try and educate your users regarding Styles. Proper use of styles will (or should) take care of any format.

"At the moment, i was creating a macro that would insert a bibliography into
the document. By clicking the button "insert bibliography", it would
automatically create a new section break and put the word "bibliography" as
the heading with appropriate header and footer. Of course, this will depend on the location of the insertion point of the cursor as the bibliography section will be created in the next page."

This can be done. However, properly done, it should NOT depend on "the location of the insertion point".

Where the bibliography goes should depend totally on whatever logic YOU (as the developer) determine it should go. In other words, properly done, the user should be able to click Insert Bibliography and it will do that regardless of where the cursor is.

This is logic. IMO, the coding part is the lesser of the tasks. Figuring our WHAT to do is harder than figuring out HOW to do it.

I will not deny that to do what you are asking is difficult. It is. It is very possible though. However, it is critical that you get your head around what Word thinks of Sections. So:

"No, Section 1 is not a cover page. "

If the cover page is the first page in the document, then...sorry, but Yes, it IS Section 1.

What you are asking about is really using the power of Word, and it can be done. What is your time frame for developing this? I am willing to help, but it will take time as it is very very important that you grasp what is actually going on.

Just as another example. Say you have your Insert Bibliography macro. WHAT is the logic? Here is how I would think of it. Assuming your placement of:

- Section n
- Bibliography (depends on user)
- Glossary (depends on user)

1. check to see if there IS a Glossary

2. if there is NOT, then go to the end of the document, insert a Section break, make the new section headers/footers LinkToPrevious = False, write the headers and footers, write "Bibliography" using an appropriate style, update the TOC.

3. If there IS a Gloassary, check that the Glossary headers and footer have LinkToPrevious = False, find the start of the Glossary Section, wriggle just before it, insert a Section break, make the new section headers/footers LinkToPrevious = False, write the headers and footers, write "Bibliography" using an appropriate style, update the TOC.


Complicated? Yes, sure.

associates
01-27-2008, 07:08 PM
Thank you for your reply.

wow :) never realised that it'd be that complicated. I knew it'd be a difficult task but not as you pointed out there. Initally i thought i could actually develop the codes by using the record macro tricks to get the codes but realised it's very limited there coz some of the functions i cannot get the codes by using that record macro method. I have to search for the VBA macro book and ask for your help to make this happen. My plan was to be able to complete the task and make it available for use within approx 1 to 2 months. but now realising how difficult it'd be, i think it'd take more than that but don't care the most important thing here is to make it happen.

Firstly, i use the quotation around a certain number of words like Section 1 just to emphasize that this is a Section. I won't use the quotation if that creates confusion in the future.

And with regard to the logic, i try to make it as simple as possible (as far as the VBA codes is concerned) but at the same time it would do the job for us.

i know that the cover page and TOC are definitely going to be at the front pages. The executive summary, bibliography and glossary are optional. So They are not there when they open the template. In other words, i want the user to add them to the document ONLY when they want to.

I like the idea when you said "Where the bibliography goes should depend totally on whatever logic YOU (as the developer) determine it should go. In other words, properly done, the user should be able to click Insert Bibliography and it will do that regardless of where the cursor is."

Does it mean you have determined where the bibliography would be located in the document beforehand? if that's the case, i believe there will be a "ready to use" template for the user to type in just the content to each of the relevant sections but what happens if a certain sections are filled out, would they be shown up in the document?

So to answer your queries

Now, how - exactly - are the changes/breaks between cover page, TOC, Exec Summary done? Are they Section Breaks? Are they PageBreaks?

i use the section break - next page for each of different sections

Gerry, i have attached a document report - the report that we desire to see in the end. It's a doc file but since it exceeds the limit the attachment allows, i have to rename it to xls. Please rename it to doc once you received it.

I greatly appreciate your help and time to help me out here. :)

Thank you in advance

gwkenny
01-28-2008, 01:08 AM
Hi,

It truly is not as difficult as it might seem, but you just have to understand how Word works.

Gerry is entirely correct though on using terminology correctly.

Gerry, the "sections" have to be divided with section breaks as, "TOC, executive summary, sections, bibliography and appendix have different footer in terms of the formatting of the pagination."

Original Poster:

"My plan was to be able to complete the task and make it available for use within approx 1 to 2 months."

It's possible. A lot has to do with how much your "system" is going to entail. It can also take quite a bit longer. I spent 9-months writing the first draft of a presentation system for an investment bank. More or less full time and I was already an expert in Word and VBA. But it encompassed integration with the document management system, graphing with Excel, incorporation of PowerPoint slides, etc...

I encourage you to think about your "system" as a whole first. Define the scope. Then limit yourself to delivering that before you expand the scope of the project.

For example, your scope could be: Creation of a new standard report encompassing standard styles, table formatting for data, charts (though you may not want to do charts on the first pass); Reformatting of existing reports to the new standard (this will be a partially automated/partially manual task); Support Utilities like replacing header/footers, changing of client logos/company logos (if you have different divisions etc...), inserting of sections, insertion of sample pages.

After you have defined the scope, then you can begin breaking down the tasks into smaller and smaller parts until you get to simple tasks you can tackle and program one at a time.

Good luck!

Oh, I'm also going to send you a pm.

p.s.: With regards to deleting one whole section, you can try this one line of code:

Selection.Sections.First.Range.Delete

This will delete the section that the selection is in. If you have multiple sections highlighted, then it will only delete the first of the highlighted sections.

If this is the only code you are going to execute per se, then you can immediately undo it with Edit Undo. But if you are going to perform other actions, you would want to save some version of the document so the deleted portion can be retrieved if necessary.

g-
gwkenny@Fin-ITSolutions.com (gwkenny@Fin-ITSolutions.com)
___________________________________

Looking for jobs big or small, drop me a line! Thanks!

fumei
01-28-2008, 01:34 AM
"It's a doc file but since it exceeds the limit the attachment allows, i have to rename it to xls."

ZIP your doc files for here. Although why they allow largish Excel files, not not Word files, I have no idea.

Well, you are heading in the right direction.

1. Dump those extra paragraph marks you are using to make space. They are not needed, and are asking for trouble.

2. USE STYLES!!!!!!!. If you are going to do ONE thing, and ONE thing only that will make life easier...use styles. Word is designed to use them, they are the core power of Word as a word-processor. Not using them weakens Word as an efficient word-processor. Using them makes Word a very efficient word-processor.

3. "They are not there when they open the template." The user should never, ever, EVER, open the template. They should USE a template. A template is cloned into a new document. What you do with afterwards can be anything you want, including removing Sections, bookmarked chunks of content...whatever. But users do not open templates.

Doing what you seem to want is not trivial, but is most certainly do-able. I have done the exact same thing many times. It is not "hard", but it does require careful and fully thought out logic....which can be hard.

fumei
01-28-2008, 01:40 AM
g-

Yes. "Define the scope." And yes, the "sections" must be defined by Sections in order to get the different footers.

associates, one option - and as this is VBA there can be many - is a simple userform that displays when you clone a new document from the template. Checkboxes for the optional "sections". User checks the ones they want, and clicks OK. The userforms sets up the document with the "sections" selected. Including the appropriate footers. These could be done as AutoText within the template.

associates
01-29-2008, 05:58 PM
Hi Gerry,

"simple userform that displays when you clone a new document from the template. Checkboxes for the optional "sections". User checks the ones they want, and clicks OK. The userforms sets up the document with the "sections" selected. Including the appropriate footers. These could be done as AutoText within the template.". This is an interesting idea.

I tried to use the AutoText method and have tested it with a couple of sections - Executive Summary and Bibliography (it works 90% because i got the section break wrong - hence, footer is wrong too)

Anyway, i find there is another issues with using the autotext. It works fine on my laptop because i build this up using my laptop. However, when putting a copy of the template on to the server in a bid that everyone in the office can access and open it, this will not work on everyone's else computers. Is there a better way of solving this problem? If not, i guess i have to use the harder way and that is writing VBA macros to make all these happen.

Thank you in advance

gwkenny
01-29-2008, 10:17 PM
However, when putting a copy of the template on to the server in a bid that everyone in the office can access and open it, this will not work on everyone's else computers. Is there a better way of solving this problem?
How to disseminate your 'Reporting System' has a number of considerations.

Hopefully your IT department is good and every machine is configured the exact same way. I've been lucky that the organizations I have worked with had good IT departments and they were able to push the initial 'Reporting System' template out as part of the login script. If there was an updated file on the network, it was pushed out to the workstation. Then when word started, the template was already in the startup directory so it would load automatically.

Can do this through the Normal.dot as well.

Another consideration is how the 'Reporting System' is going to be maintained. I also like to use Autotext, but I have worked with some lawyer firms with their boilerplate documents. Some Partners have a hard time understanding Autotext (and truly, it's not the best use of their time though it would be extremely helpful).

In many cases, I have separated out 'sections' and 'sample pages' into their own word file and put all these files in their own subdirectories on the network with specific file naming conventions. When word starts up, it looks to the network and updates local files from there. You've got to think about laptops and the fact that sometimes they will be connected to the network and sometimes not.

The downside is that someone who is given access to these directories can really mess with your 'Reporting System'.

The upside is that an average Word user can maintain the 'Reporting System' by updating the basic files that go into creating a new report, or the files that go into inserting portions, sample pages, what have you...

It doesn't require an advanced User to enter the template and replace the Autotext entry.

Additionally, if you use separate files with a file naming convention, you can code in flexibility. For example, all footer files begin with ftr_. You might have ftr_Cover, ftr_TOC, ftr_Executive_Summary, etc....

So when the User runs the code to change a footer, code goes through and scans the directory for files beginning with "ftr_". A dialog box pops up and lists the different footers available based on the files it found with an "ftr_" beginning.

So, if later you have a need for landscape pages, and you need to insert a landscape footer option, you just need to create a file with the correct landscape footer and place it in the directory with a filename like, "ftr_Main_Landscape". No additional coding required in the template to add this option.

If there is an advanced Word person on-site, then the exact same system utilizing a naming convention on Autotext entries can be done as well.

There are many ways to disseminate your 'Template' so it is available to all Users, but I urge you to think about how it will be updated. There are many ways to do that as well.

In my opinion though, you need to first focus on standardizing what is a sample generic 'Report' with clearly defined styles and formats.

I will reiterate what I said in my Private Message to you. You need to think about if this is something you WANT to do for a long time. If you create this system, they'll be coming to you to maintain, update, and expand it. It's great job security, but if this is something you don't want to take up a significant % of your time, then you need to plan accordingly.

It sounds like you are interested in Word though. So if you continue on this path, I urge you to define your scope and focus on just that before you expand it. You'll find as your knowledge grows, there are more and more ways of doing things and one might be better than another and you'll find yourself re-writing stuff (and that happens). But the reason I keep re-iterating about defining your scope is that you'll have definite results to display if someone asks about the time your are putting in (guess it's something I've learned contracting) but also it keeps you focus so things get done. It sounds now like you are tackling one problem after another as they come up, but as Gerry pointed out, you really need to define what is a 'Report' first, and that means definition of styles and page layouts.

As a first step, I recommend you solidify a generic "sample New Report" which includes defined styles and section breaks. Styles for body text, quoted text/cited text, text in tables, page headers, Titles, subtitles, tables, Headings, bullet points, portrait pages, landscape pages, letter format, A4 format...

Then after you have a generic "sample Reports" to create the "New Report" macro. This will allow you to select the different sections you want in a New Report.

Then after you've complete that, expand the scope to add support functions, like changing headers/footers. Inserting landscape pages, etc...

*****************************

NOTE: DOCUMENT YOUR CODING!!!!!!!!!!

Write explanations of your coding. After a week has gone buy, you won't remember what's going on when you look back at a routine. For every routine, I like to write the following: Description of the routine, Variables declared, Variables received, and Variables passed. I also add additional comments to large lines of complicated code.

Here's an example from some code I wrote almost a decade ago. I have since shortened my variable names to convention and my routine names:

Private Sub insSecDiv_Main()
'DESC: Main procedure that checks the environment and _
inserts a Section Divider
'VARIABLES 'DECL: 'stFileExt = Extension of the generic _
section divider page
'stMsgForErr = Message to be delivered if no file with the _
stFileExt is found
'stFileName = Filename of the generic section divider page _
to be inserted
'RECD:
'strHolder = Name of style to be referenced by styleref field
'stParentDirectory = Module level variable passed to be defined _
because DO_ModVarEnv is in Common_Pres_COde module
'PASSED:
'stParentDirectory = Null variable to be defined, and Passed to _
DO_CheckPresEnv to check the environment
'stFileExt = To DO_ChkPresDocEnv for environment checking
'stMsgForErr = To DO_ChkPresDocEnv for environment checking
'stFileName = To D0_insSecDiv procedure


But just looking at this, I know exactly what my procedure does and what variables I am using. I don't have to read the code to understand what I did a long time ago. I know this procedure calls a routine that uses a dialog box, and populates the choices in that dialog box by the filenames in a specific directory that have a file extension as defined in the stFileExt variable.

I can use this same dialog box routine to display the choices of different section divider pages, different footer choices, different header choices, different logos... etc....

___________

You probably aren't into passing many variables yet. But you should write descriptions for all your routines and comment on particularly long lines of code.

I've rambled on enough so I'll signoff here.

g-
gwkenny@Fin-ITSolutions.com (gwkenny@Fin-ITSolutions.com)
___________________________________

Looking for jobs big or small, drop me a line! Thanks!

EDIT: Adjusted the code for line breaks Tommy

fumei
01-29-2008, 10:39 PM
While gwkenny has some valid points, maintaining multiple files for portions of a document is, IMO, not the way to go.

If you have issues with accessing Autotext entries it is most likely that AutoText entries, by default, go into Normal.dot. You must explicitly transfer them to another template.

I would also recommend using a global template.

As for a starting userform, something like the attached, which is your file with a simple userform included. It is now a DOT file, a template file.

So, you would use it as a template. In other words, either double click it in Explorer (which fires Word to clone the template), or, put it in a folder that Word knows about for templates.

In any case, do not open the file, clone it...as a template should be used.

The userform displays. You choose what "sections" you want.

IMPORTANT!!!

This is NOT, repeat NOT a fully set up solution. This is very very crude. It is not fully error trapped, or fully functional. The footers are not dealt with. They certainly can be, but hey, I am not getting paid for this. This is only as a demo for one way to deal with things.

This is a reductive method. It removes bookmarked portions. This is not the only way to go about this kind of variable structure creation.

The key points here are:

1. I can not stress this enough....USE STYLES properly.

2. Build your logic in tune with your requirements.

fumei
01-29-2008, 10:47 PM
gwkenny, not that I am trying to be difficult...but....


I know this procedure calls a routine that uses a dialog box, and populates the choices in that dialog box by the filenames in a specific directory that have a file extension as defined in the stFileExt variable.

Really? Gee...I am glad you do, because I wouldn't. There is no mention of a dialog - so how would I know that there is one? There is no mention of populating anything, so how would I know that there is populating something going on.

Sorry...not buying. However, I certainly DO agree that commenting clearly is a very very good thing.


Do you REALLY use a separate file for a Section divider???? How truly bizarre.

gwkenny
01-29-2008, 11:11 PM
While gwkenny has some valid points, maintaining multiple files for portions of a document is, IMO, not the way to go.

Gerry: There are many ways to do things and many reasons why. I designed quite a number of systems maintaining multiple files for portions of a document. In my previous post, I said why and I've also included the downside as well. I can't be more honest than that.

I've also done it your way with Autotext as well!

Again, it ALL depends on what YOUR aim is. I design solutions that requires very little coding (if any) maintenance and very little advanced User knowledge needed. But there are also dangers.

I also design solutions that need advanced User knowledge which such dangers are minimized because of the expertise of the person maintaining the system.

In the situation I was noting, the Senior Partners of law firms are VERY particular on who can adjust boilerplates as they live and breath on their agreements. A misplaced "not" can bankrupt the partnership so they want sole access to adjusting the boilerplates and don't trust that to their Presentation Department. They are smart people and can understand file naming conventions and opening a document and changing the wording.

Educating each Senior Partner in a firm on how to use Autotext entries, replacing/edit entries, and updating the global template used to create all their boilerplate agreements was not an option.

For these types of clients maintaining multiple files for portions of a document is the way to go. There is absolutely no code maintenance after the system is up and tested. It is easily updateable and expandable with no additional coding. All one needs to do is adhere to the structure of the system. That doesn't require an advanced programmer or an advanced user. System can be maintained by Senior Officers of the organization.

I've displayed this type of structure to several banks as well and a few have chosen this direction, including what some consider the best Private Equity Bank in the world (The Blackstone Group).

This system is not right for everyone because of the downsides, but it has it's uses.

This system is of strict file naming conventions and directories is GREAT though for standard company templates (Memos, fax cover sheet, etc....). They all get placed in one directory. Everytime Word fires up, it scans the directory and builds the Company menu on the fly. If they add a new template, they just put it in the directory and everyone's machine is automatically updated. Conversely they can remove a template file, and it gets removed from everyone's menu choice. No need to update everyone's normal.dot and/or global templates or any recoding at all.

______________________


Jenn: You need to take Gerry's urgings to heart and define your styles/layouts for your Reports.

That should really be your scope now. This includes styles for body text, quoted text/cited text, text in tables, page headers, Titles, subtitles, tables, Headings, bullet points, portrait pages, landscape pages, letter format, A4 format...

When you have this, then you can expand the scope. But everything is truly driven by styles in Word and that will make life easier.

gwkenny
01-29-2008, 11:23 PM
gwkenny, not that I am trying to be difficult...but....

Honestly you are. Please read your words:


Really? Gee...I am glad you do, because I wouldn't. There is no mention of a dialog - so how would I know that there is one?

You are being sarcastic and demeaning. There is no need to tear anyone down. But I do welcome constructive criticism!!!!

The example I cited was to demonstrate that system can get difficult, but documentation really helps when you revisit code. That's it.


There is no mention of populating anything, so how would I know that there is populating something going on.

Sorry...not buying.

You can keep saying that till I post my entire code for this specific presentation. But again, that was not the reason why I posted it. But I will post the subroutine for you in my next post as in and of itself it's not really confidential.


Do you REALLY use a separate file for a Section divider???? How truly bizarre.

Want to talk about bizare? The first system I did was for Credit Suisse. Their presentation system was on a mainframe and I was creating it for the desktop for the first time. I had an old lady taking my printout and using a ruler to determine positioning of graphics (okay) but also the thickness of lines used in the fonts.

I really hope you have a great day! There's tons of work and tons of stuff to learn for all of us to get along together without tearing each other down!

:D

g-
gwkenny@Fin-ITSolutions.com (gwkenny@Fin-ITSolutions.com)
___________________________________

Looking for jobs big or small, drop me a line! Thanks!

gwkenny
01-29-2008, 11:28 PM
Gerry, here's the rest of the routine with my apologies to the Original Poster:

*** begin code here ***


Dim stFileExt As String
Dim stFileName As String
Dim stMsgForErr As String
Application.ScreenUpdating = False
stFileExt = "*.sdp"
stMsgForErr = "Generic Section Divider Pages"
DO_ModVarEnv stParentDirectory
If DO_CheckPresEnv(stParentDirectory) = False Then GoTo EndProcedure
If DO_ChkPresDocEnv(stFileExt, stMsgForErr) = False Then GoTo EndProcedure
If DO_DocEnv = False Then GoTo EndProcedure
If MsgBox("Please confirm the insertion of a Section Divider Page AFTER the current page", _
1, "[Investment Bank] Publishing Department") = vbCancel Then GoTo EndProcedure
Load frmInsSecDiv
frmInsSecDiv.cmdCancel.Tag = "false"
frmInsSecDiv.Show
If frmInsSecDiv.cmdCancel.Tag = "true" Then
GoTo EndProcedure
End If
stFileName = stParentDirectory & "Generic\"
stFileName = stFileName & Dir(stFileName & stFileExt)
DO_insSecDiv stFileName
ActiveDocument.Fields.Update
EndProcedure:
DO_CloseAllForms
Application.ScreenUpdating = True
End Sub
*** end code here ***

Gerry, I'm sorry, I'm not going to post any of the routines that this procedure calls. I do hope we can put this to rest and just get along.

I welcome any constructive criticism (but considering that this code is almost a decade old already it's not particularly relevant unfortunately).

g-
gwkennyATFin-ITSolutionsDOTcom (gwkenny@Fin-ITSolutions.com)
___________________________________

Looking for jobs big or small, drop me a line! Thanks!

EDIT: Tiddy up the code for line breaks Tommy

fumei
01-30-2008, 09:31 AM
My apologies. I will say nothing further.

associates
01-30-2008, 05:37 PM
Thanks to you both, Gerry and GwKenny for your helps.

Firstly, just want to say that both of your comments and helps have been really helpful in getting me to understand all the possibilities available there in office word. So let's share the ideas around :)

GwKenny, I decided to use a bit of both, coding and autotext, combination to do this. I suppose My aim here is to achieve the result without using too much of codings.

My colleagues and I have decided for the scopes - what Styles for body text, Headings, text in tables, page headers, Titles, subtitles, tables, Headings, bullet points, except for portrait pages, landscape pages, letter format, A4 format... - these are a bit too much at the moment for me. So all i'm focusing at the moment is to get the basic features to work first.

I'll get into the maintenance subject later.

This is what i have developed so far. (this is all done in template called Standard Report.dot)

1. when user double clicks on the template, the clone is open. As soon as it is open, i have a macro called autonew() that would call a function "stylesSetup". It sets up all the styles we want to use for the Headings and text. Not for the bullet points or any fancy stuffs. Then, it'd show the userform with all the sections available for them to select. In this userform, i have macros that would call the autotext to set up the document with the "sections" selected.

2. Then, in the customised menu toolbar, there are macros allowing to insert table.

That's what i have got so far.

Then, i put a copy of this template to the server so that any users who have access to the server, can access the template.

(I'll consider about setting it up so that 'Reporting System' template be distributed as part of the login script. If there was an updated file on the network, it was pushed out to the workstation. Then when word started, the template was already in the startup directory so it would load automatically) - this is again something new to me. I actually work in the IT department and am responsible for it.

But before that, i try to get the easier part to work first. Yesterday, after putting a copy of the template onto the server, i found that it works on some computers but not others. What i mean by that is when i double clicked on the template to start the document on computer-A, i could see the customised menu appearing in the toolbar, but this is not the case for other computers. I don't see any menu created in the template appearing in the toolbar. Have i done anything wrong here?

Thank you in advance

gwkenny
01-30-2008, 09:15 PM
OP:

Using the same numeric system in your post above:

1) All your new reports will be done by launching Standard Report.dot. Thus you only need to define the styles in Standard Report.dot. You do not need to create code to define the styles :)

Same with custom bullet points. Just define them in Standard Report.dot. No coding required.

2) How is the customized menu toolbar created? Is it created on the fly with code? If that's the case can we see the code? Is it part of the Standard Report.dot template? If that's the case, I don't know why they wouldn't appear. If they don't appear, is it an option when you right click on the toolbars (or do VIEW/TOOLBARS)?

SITUATION NOW

You've worked on defining the very basic styles and have created one custom menu option (and I'm assuming working on more) and are dealing with disseminating your project all at once.

I can't help but reiterate that you need to narrow your scope. You said you are in the IT department and that you and your colleagues (I'm assuming in the IT department) have defined the styles. Just an FYI, I've often found that I needed to get a Senior Officer of the organization for a final signoff.

1) Get the basic format and layout ironed out - think you've got this done, least for the test run.

2) Get the basic system up and running on one computer - This depends on what a basic system is, but you've got the creation of a New Report. Write out your custom menu tree including the options you haven't coded in yet.

3) Define the additional options you are going to use to support the basic system and code them in.

4) Now that you have your template in basic running order, talk to the person in your IT department in charge of Login scripts to get your template placed on everyone's machine in a trusted startup location. You said that was you. You can't keep the template on the network if anyone uses laptops cause when the laptop is not hooked up, it won't find the template (obviously). So you need a system where you keep the template on the network as a repository and copy it down to the local computer in a trusted startup location.
________________________

"I suppose My aim here is to achieve the result without using too much of codings."

It all depends, but it has been my experience that when you impliment a system the Users are all going to demand more and it usually entails coding. This will take a significant portion of your time in the near future. Especially after you rollout. It takes experience combined with expert knowledge of Word to setup a system that require little or no maintenance over a long period of time. Though that really depends on how 'big' and 'bad' your system is :D You can create a simplistic system and just say that nothing else can be done.

Tommy
02-02-2008, 03:52 PM
@ gwkenny I adjust everyone's code for about 60 characters - I had to use scroll bars and I have a 19" widescreen.


I'll get into the maintenance subject later.

IMHO - I have an eye towards maintenance at all times. I look at it, I think about it, I code for it, but most of all I dread it. :devil2: I am first and foremost a coder, so my opinion is code it :) Leave nothing to chance, allow the user to change anything they want - with your code. I don't really like a lot of files attached to a project, more for me (or who ever follows in my footsteps) to keep track of and maintain. I also try not to use the "fancy" features, most of the time, due to they change (with new versions) and now it is a revision to something I wish I hadn't done.:mkay For some reason the products are not always backwards compatible. Or the feture was the beginning of a newer and more better feature and it doesn't work like it used to :) but then again maybe I shouldn't start with the evaluation versions huh.:rofl:

gwkenny
02-02-2008, 06:46 PM
Tommy: Thanks for reformatting my code for the board!


IMHO - I have an eye towards maintenance at all times. I look at it, I think about it, I code for it, but most of all I dread it.

I do too, but I don't think the OP has the experience that you or I have to be able to do that adequately. That's why I keep suggesting a very narrow scope and be ready to re-write a lot of code.


:devil2: I am first and foremost a coder, so my opinion is code it :) Leave nothing to chance,

Me too. I was classically trained when I was in elementary school (my father worked for IBM). I programmed my first 'Reporting System' in WordBasic (not a lot of fun as incredibly few people besides Microsoft had any experience with the stuff).


I don't really like a lot of files attached to a project, more for me (or who ever follows in my footsteps) to keep track of and maintain.

The nice thing about this is if you really set it up right, and only give the right people access to the core files, there is NOTHING for the coder to maintain and it is EXPANDABLE. I use very few bells and whistle, a number of API calls but I code pretty tight. How many systems are expandable and maintainable without additional coding? And only by an advanced User who doesn't need to know any code?

Got a new logo? No problem, just have the admin put the file in the correct directory and it comes up as a choice. Got a new insert or sample boiler plate? No problem, just have the admin put the file in the correct directory and it's available automatically. Now supporting Europe as well as America? No problem, just have the admin put the A4 format file in the correct directory and it automatically appears on the menu as a choice when the User next starts Word.

That's a huge upside for me cause I don't have to revisit and maintain code (which to me, is the biggest pain in the ass. The fun is in designing it!).

Tommy
02-04-2008, 07:40 AM
i double clicked on the template to start the document on computer-A, i could see the customised menu appearing in the toolbar, but this is not the case for other computers. I don't see any menu created in the template appearing in the toolbar. Have i done anything wrong here?

The question here is is the security setting too high? if it is it will not allow the VBA to run and the creation of the toolbar will not happen.

Also if you plan on using the boiler plate method change the file attributes to read only and in the directories on the server make them read only. It would not keep a power user from modifing, but for the most part most users will not be able to change them and then reuse them. :) Which leads to all of the files (except the .DOT) would be stored on the server (IMHO). One place for all of it. The only probelm with this is upgrades. (ex the server name or directory structure changes)

What is the scope of this? Do you know if there are going to be 5 users or 55?

@gwkenny

I use one file, in this file I have multiple files that are un-encrypted then broken out (on the startup of the program) into many files. I encrypt it to keep anyone from changing it outside of the program. I allow edits and save the file, combine all files into one and re-encrypt it on termination. just an FYI in case you werer curious :)

gwkenny
02-05-2008, 09:58 PM
Tommy:

With regards to the Boiler Plate method... How do you handle laptops? If they are stored only on the network, then folks have to be aware they are not going to be available offsite.

As for file attributes... Thankfully the OP is in the IT department so she should be able to assign directory rights. All Users at read only and IT admins and the person in charge of the Word stuff given full access.

One of the reasons I like having pertinent templates (like a Presentation/Report generation template) as part of the User Login script is that it automatically forces it into the valid startup directory (this bypasses most problems with regards to enabling macros) and helps when you have to modify your templates and files as this will automatically disseminate your revisions.

Tommy: Regarding encryption and re-encryption of your files on program startup- YOWZA lol

Tommy
02-06-2008, 06:54 AM
Hmmm I see you assume the user actually turns the PC on and off each day. :rofl: So the login script can do its job, the user has to log off and on, the laptops don't logon to the network? :devil2:

Encyption: The reason I use it is when you have over 200 users that use your program and you have no control over anything but the app you do what you gotta do. :giggle

gwkenny
02-06-2008, 03:51 PM
lol

Yeah, I assume a lot. Most folks do turn their pc's off. But I'm also assuming a standard help desk that gives the line, "Have you turned the PC on and off? Does that solve the problem?" lol.

Laptops do logon to the network. When they are connected and start Word, my global templates that are pushed to their local startup directory will determine if it is connected to the Company network. If so, it will download updated boilerplates and supporting files to some inconspicuous space on the hard drive. If the laptop is not connected, it will run with the existing files already on the hard drive.

If everything is stored solely on the network, laptops won't have the ability to use the Boilerplates. That's why I asked how do you handle laptops?

Regarding your reason for encryption.... Very understandable, but a good system admin should be able to lock the directories from general users using group rights. Both locally and network wise. Unfortunately it takes just a little bit of planning which doesn't seem to happen in way too many IT departments :(