MsgBox with number of paragraphs formatted with a user-defined paragraph style

Dear Experts:

I would like to loop thru all paragraphs and check how many paragraphs
have been formatted with a specific user-defined paragraph style (say
user-defined-style-1). A Msg Box is to show me the numbers of
paragraphs formatted with this style.

Help is much appreciated. Thank you very much in advance. Regards,
Andreas
0
andreas
5/3/2010 1:33:05 PM
word.vba.general 1023 articles. 1 followers. Follow

4 Replies
910 Views

Similar Articles

[PageSpeed] 40

Something like

Dim oSection As Section
Dim oPara As Paragraph
Dim i As Long
i = 0
For Each oSection In ActiveDocument.Sections
    For Each oPara In oSection.Range.Paragraphs
        If oPara.Style = "user-defined-style-1" Then i = i + 1
    Next oPara
Next oSection
MsgBox i


-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"andreas" <andreas.hermle@gmx.de> wrote in message 
news:5f6a58fc-fea2-40a8-8fad-9e730a8cb749@r34g2000yqj.googlegroups.com...
> Dear Experts:
>
> I would like to loop thru all paragraphs and check how many paragraphs
> have been formatted with a specific user-defined paragraph style (say
> ). A Msg Box is to show me the numbers of
> paragraphs formatted with this style.
>
> Help is much appreciated. Thank you very much in advance. Regards,
> Andreas 


0
Graham
5/3/2010 2:27:21 PM
Do you actually need the Section?

Sub CountEm()
Dim oPara As Paragraph
Dim j As Long

For Each oPara In ActiveDocument.Paragraphs
   If oPara.Range.Style = "Yadda" Then
      j = j + 1
   End If
Next
MsgBox "There are " & j & " paragraphs using the Yadda style."
End Sub

works for me.  Not sure why you explicitly set i = 0, as it should be 0
simply by declaring it.  Although I certainly am in favour of explicitness.

Gerry

Graham Mayor wrote:
>Something like
>
>Dim oSection As Section
>Dim oPara As Paragraph
>Dim i As Long
>i = 0
>For Each oSection In ActiveDocument.Sections
>    For Each oPara In oSection.Range.Paragraphs
>        If oPara.Style = "user-defined-style-1" Then i = i + 1
>    Next oPara
>Next oSection
>MsgBox i
>
>> Dear Experts:
>>
>[quoted text clipped - 5 lines]
>> Help is much appreciated. Thank you very much in advance. Regards,
>> Andreas

-- 
Gerry

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201005/1

0
Fumei2
5/3/2010 6:04:17 PM
On 3 Mai, 16:27, "Graham Mayor" <gma...@REMOVETHISmvps.org> wrote:
> Something like
>
> Dim oSection As Section
> Dim oPara As Paragraph
> Dim i As Long
> i =3D 0
> For Each oSection In ActiveDocument.Sections
> =A0 =A0 For Each oPara In oSection.Range.Paragraphs
> =A0 =A0 =A0 =A0 If oPara.Style =3D "user-defined-style-1" Then i =3D i + =
1
> =A0 =A0 Next oPara
> Next oSection
> MsgBox i
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - =A0Word MVP
>
> My web sitewww.gmayor.com
> Word MVP web sitehttp://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
> "andreas" <andreas.her...@gmx.de> wrote in message
>
> news:5f6a58fc-fea2-40a8-8fad-9e730a8cb749@r34g2000yqj.googlegroups.com...
>
>
>
> > Dear Experts:
>
> > I would like to loop thru all paragraphs and check how many paragraphs
> > have been formatted with a specific user-defined paragraph style (say
> > ). A Msg Box is to show me the numbers of
> > paragraphs formatted with this style.
>
> > Help is much appreciated. Thank you very much in advance. Regards,
> > Andreas- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Dear Graham,

thank you very much for your professional help. It works just fine
although I have to admit, I am not quite sure why you are using the
section-object.

Regards, Andreas
0
andreas
5/5/2010 12:23:25 PM
On 3 Mai, 20:04, "Fumei2 via OfficeKB.com" <u53619@uwe> wrote:
> Do you actually need the Section?
>
> Sub CountEm()
> Dim oPara As Paragraph
> Dim j As Long
>
> For Each oPara In ActiveDocument.Paragraphs
> =A0 =A0If oPara.Range.Style =3D "Yadda" Then
> =A0 =A0 =A0 j =3D j + 1
> =A0 =A0End If
> Next
> MsgBox "There are " & j & " paragraphs using the Yadda style."
> End Sub
>
> works for me. =A0Not sure why you explicitly set i =3D 0, as it should be=
 0
> simply by declaring it. =A0Although I certainly am in favour of explicitn=
ess.
>
> Gerry
>
>
>
>
>
> Graham Mayor wrote:
> >Something like
>
> >Dim oSection As Section
> >Dim oPara As Paragraph
> >Dim i As Long
> >i =3D 0
> >For Each oSection In ActiveDocument.Sections
> > =A0 =A0For Each oPara In oSection.Range.Paragraphs
> > =A0 =A0 =A0 =A0If oPara.Style =3D "user-defined-style-1" Then i =3D i +=
 1
> > =A0 =A0Next oPara
> >Next oSection
> >MsgBox i
>
> >> Dear Experts:
>
> >[quoted text clipped - 5 lines]
> >> Help is much appreciated. Thank you very much in advance. Regards,
> >> Andreas
>
> --
> Gerry
>
> Message posted via OfficeKB.comhttp://www.officekb.com/Uwe/Forums.aspx/wo=
rd-programming/201005/1- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Dear Gerry,

it is working just fine. Thank you very much for your professional
help. Regards, Andreas
0
andreas
5/5/2010 1:10:29 PM
Reply:

Similar Artilces:

Users cannot create appointments
Hi everyone We have recently updated CRM to 3.0. Since the upgrade, everything is working ok but for one little problem. I have users in one particular BU that cannot create appointments. Users in all other BUs do not experience this problem. Also, if a move a user out of this BU, he will be able to create appointments. I have rollup 2 applied. Clues anyone? Thanks! -- GVerreault Well I'm sure you've already deduced that the issue is security related. what is the error they get? can you describe the organization/BU structure in your CRM? You said that if you move a user f...

Add contact phone number to case form
Is there a way to add the Contact Business Phone number to the Case form? The Responsible Client field shows, but not the phone number. There are a couple of ways to achieve this depending upon your requirements. You can use a JavaScript web service query from the Responsible Contact's OnChange event to populate a custom telephone number field on the case form with the appropriate field from the contact record. But if the contact's telephone number changes, the corresponding field on the case form won't get updated. Instead of displaying just the contact's full name in...

format/picture in email
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) just switched from pc to mac. <br><br>very frustrated when trying to embed pic in an email. <br> Outlook would allow edit/resize, text wrap or float and create a hyperlink hotspot over the image. Ent. doesn't seem to support any of that formatting fuctionality... <br><br>help anyone? > This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --B_3346677058_8293240 Content-type: text/plain; charset="U...

How do I change minus numbers to + numbers in a col in Excel?
Is there a way to highlight a column or a row and change all of the numbers from negative to positive or vice versa without doing the change cell by cell? Thanks "Paul L" <Paul L@discussions.microsoft.com> wrote in message news:74D3CE9E-0454-4AA5-89B8-3CA77BECA01B@microsoft.com... > Is there a way to highlight a column or a row and change all of the > numbers > from negative to positive or vice versa without doing the change cell by > cell? Thanks Put -1 in a spare cell, and Copy. Select the cells you want to change, then Paste Special/ Multiply -- David B...

Input Custom Footer Date, external site users see a different date
Hi, I have been updating an XLS worksheet with a Custom Footer Date that enter manually when the document is updated every quarter. Clients a Homebase (west coast) can see the "right" date of when the document wa updated. External users (Remote sites, mostly east coast) see the date as date when it was changed in the last quarter. Example: I change the date to 03/31/04 in Custom Footer. External User see it as 12/30/03. Any ideas to why this maybe happening??? -- Message posted from http://www.ExcelForum.com ...

Excel 2003, It wont print in landscape format
I have recently loaded Office 2003. However, Excel runs Ok, but I have noticed that it will not view or print in Landscape format. Even if you have a previous saved document from excel 2002 in landscape format, Excel 2003 will not show this document in Landscape mode. Can somebody assist..? From my experience, when there's something going on with print preview, printing, etc. it usually has to do with the print driver, I or someone else has loaded. HTH ...

Find column number
I have a table with columns headed 1 to 13 in cells A1 to m1. The rest of the table displays the answer 1 once per row with the rest of the columns in each row empty. I need to display which column the 1 appears in for each row, i'm sure there is a formula for this and any help would be much appreciated as I have over 3000 rows to get a column number for. Thanks James Put this in cell N2 (for example): =3DMATCH(1,A2:M2,0) Then you can copy it down as far as required. Hope this helps. Pete On Jul 28, 11:42=A0am, "j.farr3ll" <j.farr...@googlemail.com> wrote: > I h...

Changing date display format
This is fairly simple, but I just can't figure out where to set it. How do I change the default date display format in Money 2003? - Bruce A. Johnson in Hardisty, Alberta, Canada - Bruce@BruceJohnson.ca Control Panel > Regional Options -- Regards Bob Peel, Microsoft MVP - Money For UK tips & fixes see http://support.microsoft.com/default.aspx?scid=fh;EN-GB;mny. I do not respond to any emails that I have not specifically asked for. "Bruce A. Johnson" <Bruce@BruceJohnson.ca> wrote in message news:Xns975214AB1D3EBruceBruceJohnsonca@207.46.248.16... > This ...

CRichEditCtrl number of visible lines
Hello there. I am writing simple debugger. I need functionality in CRichEditCtrl which can tell whether a line (specified by number) is visible at certain moment. So, there is GetFirstVisibleLine(), but I could not find something that can help me to determine whether my line number is in visible area, like using some function EnsureVisible(), or something. Can somebody help me with this? Mitko ...

MsgBox and a pop up form
I have an application that pop up a form (vbModal) asking for password in order to proceed. It pops up after a period of idling. It works prettty well. The hassle comes when there is a MsgBox popping up and the user does not respond, then the modal form pop up. Now I got 2 modal things, and you cannot click anything to move on. I have been sidestepping the problem by disabling the modal form whenever I show msgbox. I am wondering if there is a better way to do this. "phil hunt" <a@abc.com> wrote in message news:i43f9i$k9b$1@speranza.aioe.org... >I have...

Sending Publisher newsletter via Outlook 2007 screws up formatting
I have been sending out monthly newsletters as email created in Publisher 2003. These look great in Outlook 2003. However, I recently installed Office 2007 and now the Publisher emailed newsletters (both Publisher 2003 and Publisher 2007) look terrible in Outlook 2007. I have tried everything I could. I have even created the newsletter on one of my machines that is still running Office 2003. The Publisher newsletter looks perfect when viewing it in Outlook 2003 but terrible when viewing it in Outlook 2007. How do I fix this? Suggest you make your newsletter a pdf file and attach i...

Numbered Items in a Cell
I am using Excel 97. Is there a way to have a numbered items inside a single cell. Thanks Manik Please be more specific as to what you would like to do....... Vaya con Dios, Chuck, CABGx3 "Manik" <m.manikandan@mailcity.com> wrote in message news:04da01c34b1e$7d53eca0$a301280a@phx.gbl... > I am using Excel 97. Is there a way to have a numbered > items inside a single cell. > > Thanks > Manik Lets say I want the following contents to be in a cell (big one): 1. First Line 2. Second Line 3. Third Line I want all the above numbered items to appear in a si...

Conditional Formatting Excel 2007
Part 1 I have a series of variable numbers in Columns B, C and D (approx 100). I want to be able to shade cells in both cols B and C when the value in the Col C cell is greater than the value in the corresponding Col B cell. Can it be done? If , help would be appreciated Part 2 I also wish to do a comparison with Col B and Col D values and would wish to have similar shading. (As far as col B is concerned, it would shade if Col C /or/ D was bigger - rather than both.) Any help would be appreciated. Tx in advance. Rob Rob, For this answer, let's assume that your table is ...

RM Change Customer Number
Hey All, I just received a request to have some of our customer numbers in receivables management to be updated with a M in front of them. Is there an easy way of doing this? Thanks Rick Look at Professional Services Tools Library. It's an additional purchase, but well worth it. -- Thanks, Brian "Rick Gittins" wrote: > Hey All, > > I just received a request to have some of our customer numbers in > receivables management to be updated with a M in front of them. > > Is there an easy way of doing this? > > Thanks > > Rick > &g...

Number zero in a cell
> This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --B_3283152995_4495907 Content-type: text/plain; charset="ISO-8859-1" Content-transfer-encoding: 8bit Hopefully this will make sense. I am adding information to a spreadsheet and when I try to input, let�s say a zip code starting with the number zero, it does not appear on the sheet. How do I make the number stay visible? I am a little rusty on my excel skills so if anyone can help me with this it would be greatly appreciated. Thank you!...

Sheet msgbox
I have a msgbox that I wish to appear when a sheet is active, I hav tried the code: Private Sub Workbook_SheetActivate But that doesnt seem to be working. Any ideas as to how to fix thi problem? Regards -- Message posted from http://www.ExcelForum.com Hi you need to put the code in the workbook module of your workbook. See http://www.cpearson.com/excel/events.htm for instructions -- Regards Frank Kabel Frankfurt, Germany > I have a msgbox that I wish to appear when a sheet is active, I have > tried the code: > Private Sub Workbook_SheetActivate > > But that doesnt se...

Uniqe number
Hello I got a table that looks something like: <pre> menuID caption parentID seq 1 Books 0 1 2 Tables 0 2 3 English 1 1 4 Spanish 1 2 </pre> This give me the option to build the menu in HTML (I don't think it's the best way but this what I could think of) and when I want to enter the next menu item under books, I need to find out what is the biggest seq value wh...

Cannot get date to format correctly
I have a problem. I keep trying to format the date in certain cells, and it keeps wanting to add the time. The date is pasted in from worksheets where I had used a NOW() formula, but I had just pasted in as values to the new worksheet. No matter what I've tried as far as changing the format, it just keeps showing the time. How can I keep the date, but get it to stop showing time? If I read it right, you just need to format the cells Right click, select format cells, General Tab, Custom (bottom of the list) and if not already provided, type in the format you want eg. dd...

Ticket numbers
I am preparing tickets for an event in MS Publisher 2002. I want each ticket to have a unique number, say from 001 to 200. How do I get Publisher to do this automatically? Thanks, Hi Mad Tony (madtony@interaccess.com), in the Microsoft� newsgroups you posted: || I am preparing tickets for an event in MS Publisher 2002. I want || each ticket to have a unique number, say from 001 to 200. How do I || get Publisher to do this automatically? || || Thanks, The following link has your information: http://www.mvps.org/publisher/training.html -- Brian Kvalheim Microsoft Office Publisher MVP Of...

maximum number of indexes per SQL table that Access (jet) can deal with?
why is there a maximum number of indexes per SQL table that Access (jet) can deal with? is it really the count of indexes + statistics? I've seen plenty of documentation that states that typically DSS systems have twice as much index space as data space.. So I don't think that it's a case of 'over-indexing' I'm just tired of a crippled Jet front end and other people making me 'temporarily drop my indexes' so that they can link to my tables using Jet. has this bug gone away with Access 2007? Is it going away with Access 2010? ...

Format Cells
I have a worksheet in which I want a column formatted so that I can put in a value that looks for like 10-11 or 2-3. If I use the Format Menu and choose Cells and specify General, as soon as I press enter, the value in the original cell changes to 11-Oct or 3-Feb and the format has changed to Custom d-mmm. I have tried selecting the column and choosing Edit-Clear-Formats but that doesn't help. I would appreciate any suggestions as to how to solve this problem. I don't think it existed when I first created the worksheet but has now appeared magically! Virginia Hi either for...

date format not change in custom
Hi, I use CONCATENATE fx to join 3 columns of data containing year month and date. I copied the column containing the CONCATENATE function and paste as value in a new column. I set custom to format as dd.mmm.yyyy in the new column (My computer regional short date format is dd/mm/yyyy). but the format didnt appear as dd.mm.yyyy. Instead, I had to edit or f2 the cell then enter to make the conversion take place. What is unique abt the date format? Rather than CONCATENATE use something like: =DATEVALUE(A1&"/"&B1&"/"C1) This will create an actua...

Auto configure outlook for exchange users
We use roaming profiles, along with outlook 2002 and exchange 2000. Is there a way to auto configure outlook for the users, instead of having to do them all individually? Many many thanks, I really need help with this. There is a way to do it using GPO's and scripts. But I use Scriptlogic logon scripts to configure the users profiles and settings for everything including Outlook. www.scriptlogic.com :-) >-----Original Message----- >We use roaming profiles, along with outlook 2002 and >exchange 2000. Is there a way to auto configure outlook >for the users, instead...

set increment increase in invoice number it
I am trying to get my invoice to increase in numbers incrementally but I have not been able to find the method used. Any suggestions? tiredstudent, A simple way would be to use something like this, you could assign it to a button, an open or before print event. Sheets("Sheet1").Range("A1").Value = _ Sheets("Sheet1").Range("A1").Value + 1 For other ways to do this or if this is going to be used in a temple have a look here http://www.mcgimpsey.com/excel/udfs/sequentialnums.html -- Paul B Always backup your data before trying something...

MsgBox
Hi, How can you insert a enter in your MsgBox? Fe. --------------------------------------------------------------------------- MsgBox prompt:="Please note, there a no files in this directory." "Please log off know, and restart the application." _ , Title:="OOCL Extractor, release version 5.1", Buttons:=vbOKOnly + vbExclamation --------------------------------------------------------------------------- This wil not work, so what is the solution for this? Thanks as always, Mischa Do you mean to wrap the message on m...