VBA select paragraphs to set style

I'm trying to automate formatting of a Table of Contents document.

How can I use VBA to find all paragraphs that do NOT include a tab followed 
by a number (page number) and change the style setting for those paragraphs? 
(These are the chapters.)  

I know how to change the style, but I'm not sure how to evaluate what the 
paragraph "contains". I'm using Word 2002 SP3.
0
Utf
11/19/2009 6:36:05 PM
word.vba.general 1023 articles. 0 followers. Follow

1 Replies
3616 Views

Similar Articles

[PageSpeed] 56

Hi,

The following macro applies the Heading 2 style to all paragraphs in a 
document that do not contain a tab followed by a number. 

Sub ApplyStyleSelectively()
    Dim prg As Paragraph

    For Each prg In ActiveDocument.Paragraphs
        If prg.Range.Find.Execute(findText:="^t^#", _
            Wrap:=wdFindStop, Forward:=True) = False Then
            prg.Style = wdStyleHeading2
        End If
    Next
End Sub

-- 
Hope this helps,
Pesach Shelnitz 


"caten" wrote:

> I'm trying to automate formatting of a Table of Contents document.
> 
> How can I use VBA to find all paragraphs that do NOT include a tab followed 
> by a number (page number) and change the style setting for those paragraphs? 
> (These are the chapters.)  
> 
> I know how to change the style, but I'm not sure how to evaluate what the 
> paragraph "contains". I'm using Word 2002 SP3.
1
Utf
11/20/2009 11:03:02 AM
Reply:

Similar Artilces:

BROWSEINFO: set (pre)selected path
Hi together, in C++.net I can do the following in a FolderBrowserDialog for the user to change f.e. the workPath for an application: FolderBrowserDialog* di=new FolderBrowserDialog(); di->RootFolder = Environment::SpecialFolder::Desktop; di->SelectedPath=workPath; In an MFC project I can do the following: BROWSEINFO bi; bi.pidlRoot = NULL; // set root to user's desktop But I did not find any possibily to pre(select) the old workPath in then structure: typedef struct _browseinfo { HWND hwndOwner; LPCITEMIDLIST pidlRoot; LPTSTR pszDisplayName; LPCTSTR lpszTi...

Outlook Today
Outlook 2002 - Outlook Today allows customizing. When I select the style names Summer and save changes it shows up for that session. Next time I start Outlook it's back at the default. Is this a bug??? Don in San Antonio <donr@att.net> wrote: > Outlook 2002 - Outlook Today allows customizing. When I select the > style names Summer and save changes it shows up for that session. > Next time I start Outlook it's back at the default. Is this a bug??? Try setting it in the registry directly. http://www.outlook-tips.net/howto/oltoday.htm -- Brian Tillman "...

OLE notes
Is there somewhere where I can set a preference on where OLE notes are stored for a company using GP 9. Right now, by default, the notes are stored in a folder on the desktop of Windows Servers 2003. Since I have multiple companies running, this is rather untidy. :-) More importantly, because of backup considerations, I want to set the default path to a location in the programs directory. To determine where OLE Notes are stored in Microsoft Dynamics GP, follow these steps: 1. Locate the dex.ini file in the folder where Microsoft Dynamics GP is installed. 2. Double-click the dex.ini f...

Need to set extra hard return
Hi, This must be a very basic thing, but I have been asked to submit a paper with extra hard returns in Word. How do I do this? Can anyone help me out please? Thanks. Viju vijuhegde wrote: > This must be a very basic thing, but I have been asked to submit a > paper with extra hard returns in Word. How do I do this? Can anyone > help me out please? Ask whomever assigned this task to explain this task. Essentially a "hard return" signifies the end of a paragraph. It's simply pressing ENTER. The "soft return" is just a way to start a new line - h...

VBA code to say Yes or No if any VBA code is present in ActiveWork
Using XL 2003 & 97 Would like hit Ctrl+Shift+V and have an answer either yes or no as to the presence of Any VBA code in the Active Workbook. I do know that about the VBA editor/Explorer or to press the Run Macro button and get a list from various sources . I would like to stay at the keyboard and process a series of macros including one to let me know if I even need to evoke the VBA explorer. TIA Dennis There is no bootstrap macro to tell you whether you have macros or not. If there were there would be no limit to virus writers. --- HTH, David McRitchie, Microsoft MVP - Excel ...

VBA and Scheduled task in Outlook
Hi, how can I: a) pull the query from somewhere and send it by e-mail automatically. E.g. I want to take a temperature table from http://www.wunderground.com/history/airport/EHAM/2009/7/10/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA where 2009/7/10 is the date of yesterday put it into an e-mail and send it automatically each day at 8 o'clock? b) if this is not possible, how can I send an e-mail with the attachment c:\Documents\query20090710.xls each day at 8 o'clock? my boss wants this automatized, I know how to write the VBA code for Excel, but don'...

Outlook 2003 drops signature settings after update
We have 3 machines out of 20 that drop the settings made to Signatures/default signature for new messages/default signature for replies and forwards whenever an Office update (probably a junk mail filter update) is installed. Any idea what causes this behavior? -KK ...

RE: Yes/No select All or select None
I have a form (continuous) where the user sees a list of all people with a yes/no checkbox beside the name. They can scroll down the list and select individuals by clicking on the Yes/No checkbox. I would like to add a button that allows the user to select all or to unselect all (select none). Any thoughts on how to accomplish this? Thank you, Kelvin Execute an Update query to set the field to Yes or No for all records. Here's the kind of code you would put into the Event Procedure for the Click event of your command button: Dim strWhere As String 'Save any changes...

My selections are locked--how do I unlock them?
I'm using Microsoft Office Home and Student 2007 and the bottom of my page says that my selections are locked. This happens when I try to do anything. The only thing I can do is open a document, but it won't let me type or copy or anything like that. Also, little paragraph symbols have appeared all over my page. Is it a trial copy that has expired? If so, time to buy. Is it a retail copy that hasn't been actived? "ChikiMongo" <ChikiMongo@discussions.microsoft.com> wrote in message news:B791BF17-B602-4297-9AED-FB3FF4F976D9@microsoft.com... : I'm...

Print, Merged Cells, and VBA
Hello I'm looking for a code that will help me with a print job for a worksheet. There are a lot of merged cells and a lot of "IF"s to be used in the VBA for range selection. Thanks in advance, Sarr ...

Use VBA to update Access table or Query from Excel
Can I use VBA to update Access table or Query from Excel? Thanks in advance Hi Leungkong, > Can I use VBA to update Access table or Query from Excel? Of course, using ADO or DAO. See: http://www.erlandsendata.no/english/index.php?d=envbadacexportado Regards, Jan Karel Pieterse Excel MVP http://www.jkp-ads.com Hi Jan, Thanks. I think ADO is what I want. But I am not only want to export from excel to access. I want to edit some data in access table. For example, Access has a table "ProductList" I want to use Excel to call the product by "Pro...

vba select field
Hi, having a button on a form, is it possible to select only some fields (all from the same table) of the current record instead of all fields? I've tried this code: RunCommand acCmdSelectRecord RunCommand acCmdCopy Forse dipende dei dati nel record. but it selects ALL fields in the form. Thank you. Remigio hi, On 10.04.2010 18:01, remigio wrote: > having a button on a form, is it possible to select only some fields > (all from the same table) of the current record instead of all fields? > I've tried this code: > > RunCommand acCmdSelectRecord &...

VLOOKUP in VBA
On the worksheet I can insert in a cell =VLOOKUP(C5, Hobokee.xls!AcsLow, 2) and it works perfectly, looks up the value in column 2 of the range named AcsLow in the same workbook. But elswhere I want in a macro to lookup the same table and assign the result to a variable BalAmt. BalAmt = VLOOKUP(AccNum, Hobokee.xls!AcsLow, 2) does not work. It gives a function not defined error on Hobokee. If instead of Hobokee I put Workbooks("Hobokee"), it gives function not defined error for VLOOKUP which it changes to VLookup. I have been overVLOOKUP in the Help file and see nothing wrong. W...

Turn pc speaker on/off with vba code
Is this possible? Thanks I found something here on how to do it withVBScript. You can probably modify it to work in VBA http://www.pcreview.co.uk/forums/thread-1468591.php -- HTH, Barb Reinhardt "David" wrote: > Is this possible? > Thanks Thanks Barb I'll have a go (I need to improve my web searching skills) "Barb Reinhardt" wrote: > I found something here on how to do it withVBScript. You can probably modify > it to work in VBA > > http://www.pcreview.co.uk/forums/thread-1468591.php > -- > HTH, > ...

Add a set number to a random entered number
I have to start a vehicle service record and am trying to add the 6000 mile service interval to the mileage at service number. EG. A B C D 1 6000 12000 2 12125 18125 3 18200 24200 etc A is the mileage at service and C is the next service due.I am trying to do this without having a cell with a line of 6000 in it and the formula eg =SUM(A1:B1) in the C cell.Is this possable?Hope some one can help. Hi =A1+6000 HTH. Best wishes Harald "Cyclops" <Cyclops@discussions.microsoft.com> skre...

Excel VBA/Macro programming for beginners
Hi all, I know a bit VB 6.0 programming. Will it help me to write exce vba/macro(same thing?).can anybody help me by providing some fre websites where i can have informations/codes for VBA/macro. Please tell me how could i make a *command Button * in a cell in th excel sheet -- sdebu_200 ----------------------------------------------------------------------- sdebu_2000's Profile: http://www.officehelp.in/member.php?userid=430 View this thread: http://www.officehelp.in/showthread.php?t=118812 Posted from - http://www.officehelp.i Try David McRitchie's "getting started with mac...

Loading a Form from VBA
Hi all, I'd like a module to open and load a form in my Access 2003 database... How can I do this? Use the OpenForm method. Look in the Help file for details. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Mike" <michael.leon.schwartz@gmail.com> wrote in message news:1184770076.109526.207900@o11g2000prd.googlegroups.com... > Hi all, I'd like a module to open and load a form in my Access 2003 > database... How can I do this? > On Jul 18, 10:58 am, "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com&g...

Excel and VBA
I am very interested in learning more about using VBA in office, especially Excel. Can you post some resources (online, books, etc) that can be used to help learn about using Visual Basic in office. Thanks! Here's a good place to start: http://www.contextures.com/xlbooks.html Does that help? *********** Regards, Ron XL2002, WinXP "Bob Sinclair" wrote: > I am very interested in learning more about using VBA in office, especially > Excel. Can you post some resources (online, books, etc) that can be used to > help learn about using Visual Basic in office. >...

Run VBA without show
I want excel to run the VBA code without showing me what it is doing. Which code should i use for that? Sub RunWithoutShow() Application.ScreenUpdating = False 'Paste the vba code here 'end of code 'Change screenupdating property to true Application.ScreenUpdating = True End Sub I hope this helps... Selva V Pasupathy For more on Excel, VBA, & other Resources Please visit: http://socko.wordpress.com You may also (inserting into quote from code example bellow from Socko) Use Application.Visible property to hide the application entirely Sub RunWithoutShow() Appli...

Record Selection
I am working with a part number that is 10-11 alpha numeric characters. I need to focus on the 8th character which represents the color of the item and make a selection as to the color. I started looking at the "Like" function, but couldn't figure out how to have it look at the 8th character only. I am using Access 2000. Any help would be appreciated. On Thu, 8 Apr 2010 13:51:02 -0700, Dmario wrote: > I am working with a part number that is 10-11 alpha numeric characters. I > need to focus on the 8th character which represents the color of the item a...

Form Controls vs VBA controls
I am new to VBA so just finding my feet, can anyone help me with th differences between an excel control (i.e. one from the form toolbox lets say a checkBox and a vba checkBox? From trying the two controls the I have noticed is that you canno capture the change event of the VBA checkbox in the code module, it ha to be done via the sheet (i.e. checkbox on sheet1, code goes in chang event on sheet1) the control is placed on, is this correct? What woul you do if you have three sheets with the same controls just differen data, do you really have to code the control 3 times? The excel control ho...

VBA Customization
Is there a way to get the name of the current company through VBA in Great Plains 8.0? Thanks for all your help. open GreatPlains. Add the current window, it will add the Toolbar then add fields choose the company name on the top left after the user id. >-----Original Message----- >Is there a way to get the name of the current company through VBA in Great >Plains 8.0? > >Thanks for all your help. > > > >. > Thanks. I tried, but I couldn't add company name to the field list. It opens up the login screen instead. Any thoughts? Thanks again. "ger...

File Selection and New file names
Question #1: When in the "Open File" dialog box of Publish 2002, the CTL and SHIFT keys do not work to select multiple files. This works in Word 2002 and Excel 2002 and also worked in Publish 2000. Is there a setting to allow this? Question #2: How do you get Publish 2002 to return to the folder of the "last" file opened when opening another file? Sometimes it returns to "My Docs", other times to the last folder (within my Docs) with apparently no logic, mostly returning to My Docs. Comment: Same as AB24U's message 1-24-05. When started using Pub...

Referencing a ComboBox in VBA
Hi, I am using Excel 2007. I want to run some code in my Workbook_Open() Sub that fills a combo box on one of my Worksheets (I will call it myCombo on mySheet). I tried the following code and it did not work: myCombo.Clear myCombo.AddItem "Item One" myCombo.AddItem "Item Two" myCombo.AddItem "Item Three" I assume that the problem is that within the Workbook_Open() Sub, the reference to myCombo is not valid. Can anyone tell me if/how I can get a valid reference to myCombo (on mySheet)? Thanks in advance, Paul Kraemer -- Paul Krae...

Setting Up Default Printer
User tries to print document from various applications. However, when their default printer has already been selected and print job is set to printer, the print jobkicks it back to the pdf writer. Is this a permission issue or what? Don't know what to do here. ...