topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday December 13, 2024, 9:06 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: Help me with MS Word styles  (Read 38562 times)

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #25 on: May 13, 2010, 08:13 PM »
i echo 40hz' sentiments on both counts.  Firstly, I have to repeat how amazing those McGhie articles are.  Not only has it calmed me down, but it has gotten me very excited about Word.  I have to honestly say that it is one of the most useful things I have come across on the internet in a long, long time.

Anyway, about 40hz somewhat off-topic point that I brought up...yes, when it comes to work, I get very goal-oriented.  I used to be goal-oriented 100% of the time and quite irritable about it.  but as I've grown older and wiser, I've learned to appreciate the process a lot more.  And what's more, I've tried my best to be less irritable about it all, and embrace both sides.  Often times now, I realize that it is wiser to appreciate the process rather than the final product. Why?  I feel that's where the socializing and interaction is taking place, and that is a beautifully human thing.  I attribute my 'ends justify the means" to my immature side now.

But, again, with work it's different.  At work, you have to get things done.  Too many people are not getting things done, i get really sensitive about it.  At some point, you have to be the ass and put on that face.  You have to.  So, please forgive me for that mode, that's my work personality!

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #26 on: May 13, 2010, 09:17 PM »
Anyway, about 40hz somewhat off-topic point that I brought up...yes, when it comes to work, I get very goal-oriented.  I used to be goal-oriented 100% of the time and quite irritable about it.  but as I've grown older and wiser, I've learned to appreciate the process a lot more.  And what's more, I've tried my best to be less irritable about it all, and embrace both sides.  Often times now, I realize that it is wiser to appreciate the process rather than the final product. Why?  I feel that's where the socializing and interaction is taking place, and that is a beautifully human thing.  I attribute my 'ends justify the means" to my immature side now.

But, again, with work it's different.  At work, you have to get things done.  Too many people are not getting things done, i get really sensitive about it.  At some point, you have to be the ass and put on that face.  You have to.  So, please forgive me for that mode, that's my work personality!

there is nothing wrong with this approach, in moderation...

unfortunately there is a real danger that you can be percieved as not actually getting anything done because your continually asking everyone else for a solution to your problems.  

And unless you can show that you've been trying to resolve an issue people can become reluctant to help because you're interrupting whatever it is they're trying to do so they can solve your problems.

please don't take this as a personal criticism.

I understood what you were getting at and it's not intended that way, it's just another point of view and something maybe worth considering...
« Last Edit: May 13, 2010, 09:27 PM by Target »

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #27 on: May 13, 2010, 10:37 PM »
Target, I understand what you are saying.  I probably am not expressing it accurately.  I'm pretty well respected at work...I know how to balance this stuff better than I'll be able to describe.

But for this thread, I apologize for my ranting.  The styles are just a sore topic with me.  I have no problem with anyone here, it's my favorite forum from top to bottom.  Also, after reading the articles by kfitting, I'm realizing my ranting was out of place, because it's me that doesn't understand how Word works, and not a fault of MS Word.

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #28 on: May 13, 2010, 11:23 PM »
Target, I understand what you are saying.  I probably am not expressing it accurately.  I'm pretty well respected at work...I know how to balance this stuff better than I'll be able to describe.

not a problem, I was worried you'd take it personally, when it wasn't meant to be.

Good thing here is that your interest has been piqued, which means you'll probably try and learn more - downside is then people will be pestering you for solutions to their problems :Thmbsup:

For all the negative stuff we see and hear about all things MS, at the end of the day their office suite is incredibly capable and powerful if we only knew how to use it to it's fullest (I know I wish I did  :-[)     

40hz

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 11,859
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #29 on: May 14, 2010, 04:31 AM »
I'm pretty well respected at work...

And here. (I'd hire you.)  :)


superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #30 on: May 14, 2010, 08:46 AM »
And here. (I'd hire you.)  :)
:-[ Thanks!

For all the negative stuff we see and hear about all things MS, at the end of the day their office suite is incredibly capable and powerful if we only knew how to use it to it's fullest (I know I wish I did  :-[)     
You know, this exact thought was probably the biggest lesson in all of this for me.  I have the tendency to bash the big time companies, not to mention my consistent railing against Word.  But now, I'm realizing that, yes, it is a powerful program.  It's me that has to learn how to use it.  And I don't know why that wasn't my attitude to begin with.  After all, software is a tool, it's up to you to learn to use it or even want to use it.  Anyway, this has all been very good for me.

kfitting

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 593
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #31 on: May 14, 2010, 11:40 AM »
Agreed on the MS bashing, way too many do it.  With the caveat that I wish their updates would address some of the actual deficiencies in their products...

Word is amazingly powerful (I also only realized it after reading those links), but the problem is styles are somewhat finicky when you start to use them among multiple documents, the document combiner thingy (there is a feature that lets you treat multiple documents as one) corrupts files... why does Microsoft have awesome ideas and then not fully implement them?  

Excel has (as far as I have seen, havent checked 2007) an 8 level grouping limitation, a 4000 style (expanded in 2007, but not fixed) limitation that can render a workbook unopenable (see Too Many Formats Error), and there is no way (that I've seen) to manipulate Excel Lists from VBA.

These are the things that I dont like about Office.... immense power, features, etc, but some nasty little niggles in there just when you thought you figured something out!

But, yes, the products are very capable.  Particularly once you start to think like them.
« Last Edit: May 14, 2010, 11:42 AM by kfitting »

Gwen7

  • Participant
  • Joined in 2009
  • *
  • Posts: 134
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #32 on: May 14, 2010, 01:54 PM »
But, yes, the products are very capable.  Particularly once you start to think like them.

wow! just like me.  ;-)


superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #33 on: May 14, 2010, 02:59 PM »
As a sidenote:
I am so glad to have a discussion that is impartial and rational about this topic.  Usually, Microsoft topics quickly deteriorate into a MS bashfest, or an open Office vs. MS thing, even if that has nothing to do with the subject.  Same goes for anything about Apple vs. PC.  So I appreciate learning about the many strengths and useful features of Word.

40hz

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 11,859
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #34 on: May 14, 2010, 03:10 PM »
Usually, Microsoft topics quickly deteriorate into a MS bashfest, or an open Office vs. MS thing, even if that has nothing to do with the subject.

That might be partly because Apple and "Darth Jobs" have finally come out of the closet as the new Evil Empire. They've demonized Microsoft (and everybody else) for so long they've become completely blind to the fact they're now more insular and arrogant than Microsoft ever dreamed of being.

"Battle not with monsters, lest ye become a monster, and if you gaze into the abyss, the abyss gazes also into you." -Friedrich Neitzsche

It's become so obvious that even Apple's biggest fanboys are having trouble keeping up the pretense it isn't true.

Suddenly Mr. Bill and 'Monkeyboy' Steve Balmer don't seem quite so bad in comparison. ;D

« Last Edit: May 14, 2010, 03:16 PM by 40hz »

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #35 on: May 14, 2010, 03:42 PM »
Heh...yeah.

Quick problem/question:
I'm writing my manual right now, and I cannot figure out to make a macro that will update ALL the fields, especially the table of contents...all in one click.  I've scoured the web, and used all the things they say to try, but none of them work.

It's very simple.  To update everything, you have to press Ctrl-A (to select all) and then F9 (to update).  But a dialog comes up asking if you want to update the entire table or just the page numbers.  So I select the entire table, and that's it.  That works fine.

but I'm trying to make that a macro and it won't work.  I recorded the whole process, and that didn't work.  Then I used a code I found on the web, which they say works, but it doesn't for me:
Code: Visual Basic [Select]
  1. Sub UpdateAllFields()
  2. Dim oStory As Range
  3. Dim oField As Field
  4.   For Each oStory In ActiveDocument.StoryRanges
  5.     For Each oField In oStory.Fields
  6.       oField.Update
  7.     Next oField
  8.   Next oStory
  9. End Sub

If anyone can help me, please advise.  Thank you.

EDIT:

I found the following code, and it works for the table of contents.  I don't know if it works fro all fields of all type, but it works for the TOC, so I'm happy for now:
Code: Visual Basic [Select]
  1. Sub UpdateAllTOCs()
  2. For Each toc In ActiveDocument.TablesOfContents
  3. toc.Update
  4. Next toc
  5. End Sub
« Last Edit: May 14, 2010, 03:55 PM by superboyac »

kfitting

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 593
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #36 on: May 14, 2010, 04:16 PM »
Hmmm... dont know.  I have extensive Excel VBA experience, and minimal Word.  However, I would look at what Ranges are in Word.  By cycling through them you may be limiting your search too much.  This link may help... dont know: Word Object Model

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #37 on: May 14, 2010, 05:00 PM »
Hmmm... dont know.  I have extensive Excel VBA experience, and minimal Word.  However, I would look at what Ranges are in Word.  By cycling through them you may be limiting your search too much.  This link may help... dont know: Word Object Model
I have no idea what you're talking about, and i don't understand the article.  Is this in reference to my update all fields issue above?  Are you saying the code I posted doesn't work?  All i know is that I tried several things, and that last one is the only one that worked.  Do you have anything better, or do you see a problem with it?

daddydave

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 867
  • test
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #38 on: May 14, 2010, 05:01 PM »
I found the following code, and it works for the table of contents.  I don't know if it works fro all fields of all type, but it works for the TOC, so I'm happy for now:
Code: Visual Basic [Select]
  1. Sub UpdateAllTOCs()
  2. For Each toc In ActiveDocument.TablesOfContents
  3. toc.Update
  4. Next toc
  5. End Sub
Good for you. I actually gave it a shot and I couldn't get anything to work including this code which is supposed to work according to the help file. I hate VBA.
Code: Visual Basic [Select]
  1. ActiveDocument.Fields.Update
« Last Edit: May 14, 2010, 05:04 PM by daddydave »

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #39 on: May 14, 2010, 05:12 PM »
daddydave, mine worked for me, but I'm using Word 2007.  I'm not sure what version you are using.  I know some of the articles I came across were written a few years ago, and they don't always specify what versions of Word they are using.  There are also issues with macro settings and security to consider.  In my limited experience, the options interface for Word (and Office 20070 is a mess.  Too many random places to change stuff.  it's not logical or intuitive at all.  You have a window, then a tab on the side for customize, then you go there, and there's another button labeled "customize" to edit keyboard shortcuts.  Geez.

kfitting

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 593
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #40 on: May 14, 2010, 05:43 PM »
What I was trying to say is that your original code was looking inside range objects.  I dont know the Word Object model well enough to know if your fields are contained within the ranges you're looping through. 

The article I linked to gives a high level overview of the object model.  For example, in excel you have Workbooks, worksheets, ranges, and cells (among hundreds of other things). You can loop through all worksheets in a workbook, all cells in a worksheet, etc etc. 

For Word, I dont know where fields are "kept."  Sorry, I dont know the object model well enough, nor have the time tonight to look at it further.

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #41 on: May 14, 2010, 06:49 PM »
What I was trying to say is that your original code was looking inside range objects.  I dont know the Word Object model well enough to know if your fields are contained within the ranges you're looping through. 

The article I linked to gives a high level overview of the object model.  For example, in excel you have Workbooks, worksheets, ranges, and cells (among hundreds of other things). You can loop through all worksheets in a workbook, all cells in a worksheet, etc etc. 

For Word, I dont know where fields are "kept."  Sorry, I dont know the object model well enough, nor have the time tonight to look at it further.

Ok, I sort of get it.  I keep that in mind as a resource if i have to start messing around more with VB.  Eesh, I hope not.  I'll bet someone at work is pretty good with VB.

AndyM

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 616
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #42 on: May 14, 2010, 09:44 PM »
I'll bet someone at work is pretty good with VB.

VBA Express, like DonationCoder for vba.  Someone will always answer your question and will often write some (or a lot) of code:

http://vbaexpress.com/forum/


AndyM

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 616
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #43 on: May 14, 2010, 09:50 PM »
For all the negative stuff we see and hear about all things MS, at the end of the day their office suite is incredibly capable and powerful if we only knew how to use it to it's fullest (I know I wish I did  :-[)     
You know, this exact thought was probably the biggest lesson in all of this for me.  I have the tendency to bash the big time companies, not to mention my consistent railing against Word.  But now, I'm realizing that, yes, it is a powerful program.  It's me that has to learn how to use it.  And I don't know why that wasn't my attitude to begin with.  After all, software is a tool, it's up to you to learn to use it or even want to use it.  Anyway, this has all been very good for me.

This was my story then, and I'm sticking with it  8):

https://www.donationcoder.com/forum/index.php?topic=5372.msg49315#msg49315

kfitting

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 593
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #44 on: May 17, 2010, 08:17 AM »
Here is a page that shows why this can be different for different people.  Update Fields VBA

Going back to the article on the way Word thinks, each compartment is a container for different things.  Fields could possibly go in many of the different compartments, depending on how (and where) you inserted the field.  In the code SuperBoyAC first posted, you loop through all Word ranges, look in each range's Fields collection, and then cycle through those fields. 

In the first reply of the webpage I just linked to, the user loops through each field in the Document's Fields collection... which is different than what the first code does.

It's all about object hierarchies, and I agree can be very very confusing.  However, dont go bashing VB for this problem!  ;)  This is a "problem" with any object-oriented language/application.  You can bash MS for making the Word Object Model so complex, but VB/VBA is not at fault here.  If you try to script Word through any com enabled language you will have to use the same types of object references.

Without your document in front of me I dont know which container the fields you are trying to update are in.  That's where the Object Model map can come in handy (I dont think the one I linked to above is the full map):  it shows you the object hierarchies and where each piece can be located.

Hope that helps explain... I doubt it solves the problem.

kfitting

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 593
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #45 on: May 17, 2010, 08:22 AM »
Quick update: found this link which is another way of updating fields.  It appears to be closer to what SuperBoyAC is doing by hand. 

Link: Update all fields

Code:
Sub UpdateAll()
     
    Dim myRange
     
    Set myRange = Selection.Range
     
    Selection.WholeStory
    Selection.Fields.Update
     
    myRange.Select
     
End Sub

Notice that this is using the Selection.WholeStory object... different from the other examples I've seen above.

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #46 on: May 17, 2010, 09:28 AM »
kfitting, the code above does not work for me.  What's worse, the code I pasted above that I said worked on Friday, well, it doesn't work anymore either.  I get a "cant find object or library" error now.

This is so frustrating.  Why is it so hard to create a shortcut to update all fields?  Surely, this is a very common thing.  I mean, if I am using it this much on my very first attempt to do anything with Word, it has to be a very common thing.

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #47 on: May 17, 2010, 09:36 AM »
I don't understand why none of these macros work.  Maybe I'm doing something wrong.  I have a table of contents that is entirely made of fields...I got it from John McGhie's template.  None of these macros work in updating the TOC.  Well, the second one I listed worked on Friday, but not anymore.

kfitting

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 593
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #48 on: May 17, 2010, 10:00 AM »
The error you describe is usually because the com references are not set correctly.  If you go into the VBE, click on Tools -> References.  You should see at least the following references with a checkmark. 

Visual Basic for Applications
Microsoft Word 11.0 Object Library
OLE Automation
Microsoft Office 11.0 Object Library

Another way to troubleshoot this is to click Debug -> Compile Project.  Sometimes Office apps will throw library errors for problems that dont involve the library.  Compiling will usually catch these errors.


Regarding the initial problem... I dont quite understand what's going on.  I looked McGhie's template and he's using an actual TOC object (I think, if I understand the object correctly).  As setup in the template, the TOC object does not use fields.  I found this by checking the UseFields property of the TOC object... by slightly modifying the code that worked for you on Friday:

Sub UpdateAllTOCs1()
    Dim toc As TableOfContents
    For Each toc In ActiveDocument.TablesOfContents
        toc.Update
        msgbox "TOC Uses Fields: " & toc.UseFields
    Next toc
End Sub

What I think this means is that for your situation (trying to update the TOC of your document) you should just have to use the code that worked for you on Friday.  Try the two fixes I listed above and see if that enables your script to run.

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
Re: Help me with MS Word styles
« Reply #49 on: May 17, 2010, 10:13 AM »
Thanks kfitting, the code you gave works.  But it gives an error at the end for me:
screenshot_20100517081228.png

Forgive me if I don't understand the things you are saying.  I'm half trying to learn this stuff on the job, and half trying to get it done.  In about 2 hours, my supervisor is going to come to me and ask why I've only done 10 pages in two days!