Book

Suggestions


Enter your email address:

Delivered by FeedBurner


Home Page

Bloglines

1906
CelebrateStadium
2006


OfficeZealot

Scobleizer

TechRepublic

AskWoody

SpyJournal












Subscribe here
Add to 

My Yahoo!
This page is powered by Blogger. Isn't yours?

Host your Web site with PureHost!


eXTReMe Tracker
  Web http://www.klippert.com



  Wednesday, April 16, 2008 – Permalink –

Word Ranges

Pre-defined locations



When entries are made in a document, Word creates a Story Range to identify what part of the document is being used. These ranges can be used in macros to search for items , change text, or other actions.


This macro, for instance, changes the text in just the header of the first section:

Sub HeaderFooterObject()
Dim MyText As String
MyHeaderText = "This would be your text"
With ActiveDocument.Sections(1)
.Headers(wdHeaderFooterPrimary).Range.Text = MyHeaderText
End With
End Sub


When you use Edit>Replace in Word, it does a fine job of locating all occurrences of the target in the body of the document or in the header or footer.


Something fails, however, when you record the action and try to run it as a macro. To make it work, you must loop through the built in ranges of a Word document.


The exercise is interesting if only for the exposure to the built in ranges such as:

  • wdCommentsStory
  • wdEndnotesStory
  • wdEvenPagesFooterStory
  • wdEvenPagesHeaderStory
  • wdFirstPageFooterStory
  • wdFirstPageHeaderStory
  • wdFootnotesStory
  • wdMainTextStory
  • wdPrimaryFooterStory
  • wdPrimaryHeaderStory

    and
  • wdTextFrameStory.


See this article for more information:

Word.MVPS.org:
Find and replace with VBA


Also:

Microsoft KB
VBA macro examples to insert text into a document



See all Topics

Labels: , , ,


<Doug Klippert@ 7:14 AM

Comments: Post a Comment


  Monday, June 18, 2007 – Permalink –

Convert List Numbers to Text

Pesky lists


Applying the list numbering style to paragraphs is easy. The problem is that if the style is removed, the numbers disappear as well.

The same thing is true with bullets.

The following macro will change the list numbers and LISTNUM fields to text and the bullets to a symbol font.


Sub NoAutoNum()
ActiveDocument.ConvertNumbersToText
End Sub


You can now do such things as individually format numbers and bullets.

The action is not reversible, so either use Undo right away, or use it on a copy of the original.

ConvertNumbersToText

Also see
JWOlsen.com



See all Topics

Labels: ,


<Doug Klippert@ 7:20 AM

Comments: Post a Comment


  Saturday, March 31, 2007 – Permalink –

Comment Code

Edit toolbar



You'll many times want to change blocks of code to comments in VBA modules; temporarily convert a block of VBA code to comments so that it's ignored during a trial run. Inserting an apostrophe before each line of code is a bother. Office 2000+ simplifies this task by letting you convert a block of code to comments with a click of a button.

Open any module in the Visual Basic Editor (VBE), and then choose View>Toolbars and choose Edit from the menu bar to display the Edit toolbar.

Select the lines of code that you want to turn into comments. Then, click the Comment Block button on the Edit toolbar (it's the sixth button in from the RIGHT end of the toolbar).
Each line of the selected code is now preceded with an apostrophe.




To convert the comments back to executable code, select the appropriate lines and click the Uncomment Block button, which is immediately to the right of the Comment Block button.
This, of course, works in any application that uses the VBE.

Ross, suggested that two or three apostrophes (sometimes called inverted commas) be placed around existing comments. When the Comment Block is used, the original comments will not be removed.



See all Topics

Labels: ,


<Doug Klippert@ 7:02 AM

Comments: Post a Comment


  Thursday, February 01, 2007 – Permalink –

Look for Bullets

Find lists


Unless you have used a style to create a bulleted list, it is difficult to search for them.

This macro locates any bulleted list (wdListBullet) in your document.


Sub FindBullet()
Dim rngTarget As Word.Range
Dim oPara As Word.Paragraph

Set rngTarget = Selection.Range
With rngTarget
Call .Collapse(wdCollapseEnd)
.End = ActiveDocument.Range.End

For Each oPara In .Paragraphs
If oPara.Range.ListFormat.ListType = _
WdListType.wdListBullet Then
oPara.Range.Select
Exit For
End If
Next
End With
End Sub

Other choices might be:
wdListListNumOnly
ListNum fields that can be used in the body of a paragraph.

wdListMixedNumbering
Mixed numeric list.

wdListNoNumbering
List with no bullets, numbering, or outlining.

wdListOutlineNumbering
Outlined list.

wdListPictureBullet
Picture bulleted list.

wdListSimpleNumbering
Simple numeric list.



For other macros see Tribbs.co.uk



See all Topics

Labels:


<Doug Klippert@ 5:33 AM

Comments: Post a Comment