Word get all text

In Word, you can select all text in a document (Ctrl+A), or select specific text or items in a table by using the mouse or keyboard. You can also select text or items that are in different places. For example, you can select a paragraph on one page and a sentence on a different page.

Select all text

  1. Click anywhere within the document.

  2. Press Ctrl+A on your keyboard to select all text in the document.

Select specific text

You can also select a specific word, line of text, or one or more paragraphs.

  1. Place your cursor in front of the first letter of the word, sentence, or paragraphs you want to select.

  2. Click and hold while you drag your cursor to select the text you want.

Other ways to select text

  • To select a single word, quickly double-click that word.

  • To select a line of text, place your cursor at the start of the line, and press Shift + down arrow.

  • To select a paragraph, place your cursor at the start of the paragraph, and press Ctrl + Shift + down arrow.

Select text by using the mouse

Select text in the body of a document

Notes: To select an entire document, do one of the following:

  • On the Home tab, in the Editing group, click Select, and then click Select All.

  • Move the pointer to the left of any text until it turns into a right-pointing arrow, and then triple-click.

To select

Do this

Any amount of text

Click where you want to begin the selection, hold down the left mouse button, and then drag the pointer over the text that you want to select.

A word

Double-click anywhere in the word.

A line of text

Move the pointer to the left of the line until it changes to a right-pointing arrow, and then click.

A sentence

Hold down CTRL, and then click anywhere in the sentence.

A paragraph

Triple-click anywhere in the paragraph.

Multiple paragraphs

Move the pointer to the left of the first paragraph until it changes to a right-pointing arrow, and then press and hold down the left mouse button while you drag the pointer up or down.

A large block of text

Click at the start of the selection, scroll to the end of the selection, and then hold down SHIFT while you click where you want the selection to end.

An entire document

Move the pointer to the left of any text until it changes to a right-pointing arrow, and then triple-click.

Headers and footers

In Print Layout view, double-click the dimmed header or footer text. Move the pointer to the left of the header or footer until it changes to a right-pointing arrow, and then click.

Footnotes and endnotes

Click the footnote or endnote text, move the pointer to the left of the text until it changes to a right-pointing arrow, and then click.

A vertical block of text

Hold down ALT while you drag the pointer over the text.

A text box or frame

Move the pointer over the border of the frame or text box until the pointer becomes a four-headed arrow, and then click.

Select items in a table

To select

Do this

The contents of a cell

Click in the cell. Under Table Tools, click the Layout tab. In the Table group, click Select, and then click Select Cell.

The contents of a row

Click in the row. Under Table Tools, click the Layout tab. In the Table group, click Select, and then click Select Row.

The contents of a column

Click in the column. Under Table Tools, click the Layout tab. In the Table group, click Select, and then click Select Column.

The contents of multiple cells, rows, or columns

Click in a cell, a row, or a column and then hold the left mouse button down while you drag across all the cells, rows, or columns that contain the content that you want to select. To select the contents of cells, rows, or columns that are not next to each other, click in the first cell, row, or column, press CTRL, and then click the additional cells, rows, or columns that contain the content that you want to select.

The contents of an entire table

Click in the table. Under Table Tools, click the Layout tab. In the Table group, click Select, and then click Select Table.

Select text in different places

You can select text or items in a table that are not next to each other. For example, you can select a paragraph on one page and a sentence on a different page.

  1. Select some text or an item in a table.

  2. Hold down CTRL while you select any additional text or item in a table that you want.

Select text in Outline view

To view your document in Outline view, click the View tab, and then click Outline in the Document Views group.

To select

Move the pointer to

A heading

The left of the heading until it changes to a right-pointing arrow, and then click.

A heading, its subheading, and body text

The left of the heading until it changes to a right-pointing arrow, and then double-click.

A paragraph of body text

The left of the paragraph until it changes to a right-pointing arrow, and then click.

Multiple headings or paragraphs of body text

The left of the text until it changes to a right-pointing arrow, and then drag up or down.

Notes: 

  • In Outline view, clicking once to the left of a paragraph selects the entire paragraph instead of a single line.

  • If you select a heading that includes collapsed subordinate text, the collapsed text is also selected (even though it is not visible). Any changes that you make to the heading — such as moving, copying, or deleting it — also affect the collapsed text.

Select text by using the keyboard

Select text in the body of a document

Note: To select an entire document, press CTRL+A.

To select

Do this

One character to the right

Press SHIFT+RIGHT ARROW.

One character to the left

Press SHIFT+LEFT ARROW.

A word from its beginning to its end

Place the insertion point at the beginning of the word, and then press CTRL+SHIFT+RIGHT ARROW.

A word from its end to its beginning

Move the pointer to the end of the word, and then press CTRL+SHIFT+LEFT ARROW.

A line from its beginning to its end

Press HOME, and then press SHIFT+END.

A line from its end to its beginning

Press END, and then press SHIFT+HOME.

One line down

Press END, and then press SHIFT+DOWN ARROW.

One line up

Press HOME, and then press SHIFT+UP ARROW.

A paragraph from its beginning to its end

Move the pointer to the beginning of the paragraph, and then press CTRL+SHIFT+DOWN ARROW.

A paragraph from its end to its beginning

Move the pointer to the end of the paragraph, and then press CTRL+SHIFT+UP ARROW.

A document from its end to its beginning

Move the pointer to the end of the document, and then press CTRL+SHIFT+HOME.

A document from its beginning to its end

Move the pointer to the beginning of the document, and then press CTRL+SHIFT+END.

From the beginning of a window to its end

Move the pointer to the beginning of the window, and then press ALT+CTRL+SHIFT+PAGE DOWN.

The entire document

Press CTRL+A.

A vertical block of text

Press CTRL+SHIFT+F8, and then use the arrow keys. Press ESC to turn off the selection mode.

The nearest character

Press F8 to turn on selection mode, and then press LEFT ARROW or RIGHT ARROW; press ESC to turn off the selection mode.

A word, a sentence, a paragraph, or a document

Press F8 to turn on selection mode, and then press F8 once to select a word, twice to select a sentence, three times to select a paragraph, or four times to select the document. Press ESC to turn off the selection mode.

Select items in a table

To select

Do this

The contents of the cell to the right

Press TAB.

The contents of the cell to the left

Press SHIFT+TAB.

The contents of adjacent cells

Hold down SHIFT while you repeatedly press the appropriate arrow key until you’ve selected the contents of all the cells that you want.

The contents of a column

Click in the column’s top or bottom cell. Hold down SHIFT while you repeatedly press the UP ARROW or DOWN ARROW key until you have selected the contents of the column.

The contents of an entire table

Click in the table, and then press ALT+5 on the numeric keypad (with NUM LOCK off).

Stop selecting the entire word

  1. Click the File tab, and then click Options.

  2. Click Advanced.

  3. Under Editing options, clear the checkbox next to When selecting, automatically select entire word.

Important: 
Office 2007 is no longer supported. Upgrade to Microsoft 365 to work anywhere from any device and continue to receive support.

Upgrade now

Select text by using the mouse

Select text in the body of a document

Note: To select an entire document, do one of the following:

  • On the Home tab, in the Editing group, click Select, and then click Select All.

    Word Ribbon Image

  • Move the pointer to the left of any text until it turns into a right-pointing arrow, and then triple-click.

To select

Do this

Any amount of text

Click where you want to begin the selection, hold down the left mouse button, and then drag the pointer over the text that you want to select.

A word

Double-click anywhere in the word.

A line of text

Move the pointer to the left of the line until it changes to a right-pointing arrow, and then click.

A sentence

Hold down CTRL, and then click anywhere in the sentence.

A paragraph

Triple-click anywhere in the paragraph.

Multiple paragraphs

Move the pointer to the left of the first paragraph until it changes to a right-pointing arrow, and then press and hold down the left mouse button while you drag the pointer up or down.

A large block of text

Click at the start of the selection, scroll to the end of the selection, and then hold down SHIFT while you click where you want the selection to end.

An entire document

Move the pointer to the left of any text until it changes to a right-pointing arrow, and then triple-click.

Headers and footers

In Print Layout view, double-click the dimmed header or footer text. Move the pointer to the left of the header or footer until it changes to a right-pointing arrow, and then click.

Footnotes and endnotes

Click the footnote or endnote text, move the pointer to the left of the text until it changes to a right-pointing arrow, and then click.

A vertical block of text

Hold down ALT while you drag the pointer over the text.

A text box or frame

Move the pointer over the border of the frame or text box until the pointer becomes a four-headed arrow, and then click.

Select items in a table

To select

Do this

The contents of a cell

Click in the cell. Under Table Tools, click the Layout tab. In the Table group, click Select, and then click Select Cell.

The contents of a row

Click in the row. Under Table Tools, click the Layout tab. In the Table group, click Select, and then click Select Row.

The contents of a column

Click in the column. Under Table Tools, click the Layout tab. In the Table group, click Select, and then click Select Column.

The contents of multiple cells, rows, or columns

Click in a cell, a row, or a column and then hold the left mouse button down while you drag across all of the cells, rows, or columns that contain the content that you want to select. To select the contents of cells, rows, or columns that are not next to each other, click in the first cell, row, or column, press CTRL, and then click the additional cells, rows, or columns that contain the content that you want to select.

The contents of an entire table

Click in the table. Under Table Tools, click the Layout tab. In the Table group, click Select, and then click Select Table.

Select text in different places

You can select text or items in a table that are not next to each other. For example, you can select a paragraph on one page and a sentence on a different page.

  1. Select some text or an item in a table.

  2. Hold down CTRL while you select any additional text or item in a table that you want.

Select text in Outline view

To view your document in Outline view, click the View tab, and then click Outline in the Document Views group.

To select

Move the pointer to

A heading

The left of the heading until it changes to a right-pointing arrow, and then click.

A heading, its subheading, and body text

The left of the heading until it changes to a right-pointing arrow, and then double-click.

A paragraph of body text

The left of the paragraph until it changes to a right-pointing arrow, and then click.

Multiple headings or paragraphs of body text

The left of the text until it changes to a right-pointing arrow, and then drag up or down.

Notes: 

  • In Outline view, clicking once to the left of a paragraph selects the entire paragraph instead of a single line.

  • If you select a heading that includes collapsed subordinate text, the collapsed text is also selected (even though it’s not visible). Any changes that you make to the heading — such as moving, copying, or deleting it — also affect the collapsed text.

Select text by using the keyboard

Select text in the body of a document

Note: To select an entire document, press CTRL+A.

To select

Do this

One character to the right

Press SHIFT+RIGHT ARROW.

One character to the left

Press SHIFT+LEFT ARROW.

A word from its beginning to its end

Place the insertion point at the beginning of the word, and then press CTRL+SHIFT+RIGHT ARROW.

A word from its end to its beginning

Move the pointer to the end of the word, and then press CTRL+SHIFT+LEFT ARROW.

A line from its beginning to its end

Press HOME, and then press SHIFT+END.

A line from its end to its beginning

Press END, and then press SHIFT+HOME.

One line down

Press END, and then press SHIFT+DOWN ARROW.

One line up

Press HOME, and then press SHIFT+UP ARROW.

A paragraph from its beginning to its end

Move the pointer to the beginning of the paragraph, and then press CTRL+SHIFT+DOWN ARROW.

A paragraph from its end to its beginning

Move the pointer to the end of the paragraph, and then press CTRL+SHIFT+UP ARROW.

A document from its end to its beginning

Move the pointer to the end of the document, and then press CTRL+SHIFT+HOME.

A document from its beginning to its end

Move the pointer to the beginning of the document, and then press CTRL+SHIFT+END.

From the beginning of a window to its end

Move the pointer to the beginning of the window, and then press ALT+CTRL+SHIFT+PAGE DOWN.

The entire document

Press CTRL+A.

A vertical block of text

Press CTRL+SHIFT+F8, and then use the arrow keys. Press ESC to turn off the selection mode.

The nearest character

Press F8 to turn on selection mode, and then press LEFT ARROW or RIGHT ARROW; press ESC to turn off the selection mode.

A word, a sentence, a paragraph, or a document

Press F8 to turn on selection mode, and then press F8 once to select a word, twice to select a sentence, three times to select a paragraph, or four times to select the document. Press ESC to turn off the selection mode.

Select items in a table

To select

Do this

The contents of the cell to the right

Press TAB.

The contents of the cell to the left

Press SHIFT+TAB.

The contents of adjacent cells

Hold down SHIFT while you press the appropriate arrow key repeatedly until you have selected the contents of all of the cells that you want.

The contents of a column

Click in the column’s top or bottom cell. Hold down SHIFT while you press the UP ARROW or DOWN ARROW key repeatedly until you have selected the contents of the column.

The contents of an entire table

Click in the table, and then press ALT+5 on the numeric keypad (with NUM LOCK off).

Stop selecting the entire word

  1. Click the Microsoft Office Button Office button image, and then click Word Options.

  2. Click Advanced.

  3. Under Editing options, clear the check box next to When selecting, automatically select entire word.

I’m not asking for «select All» texts in MS Word! neither using «CTRL» to select! or Even «Find». Ok?
My Question is : How Can I select all the words having e.g. «Home»
e.g.

I’m Going Home. I’m Coming Home. I love My Home.

I want to select all these «Home» and change their colors to RED (e.g.).

In My Case, The word I’ve been working on is repeated 1000 times. I can’t select them one by one!

If this is not Possible, Is there a word processor can solve my problem?

I Need Your Help! Thanks A lot

asked Nov 21, 2016 at 17:19

AndroidDev's user avatar

enter image description here

You can use find and replace all for that. Click the More > > button, which will then turn into less, and you can click on format which will allow you to adjust the font and its color then hit replace all.

enter image description here

answered Nov 21, 2016 at 17:23

Neo's user avatar

NeoNeo

3,2897 gold badges35 silver badges44 bronze badges

2

You want «Find and Replace»: CTRL-H.

https://support.office.com/en-us/article/Find-and-replace-text-and-other-data-in-a-Word-document-c6728c16-469e-43cd-afe4-7708c6c779b7

«To search for text with specific formatting, type the text in the Find what box. To find formatting only, leave the box blank.

Click Format, and then select the formats that you want to find and replace. For example, to find highlighted text, click Format > Highlight; to find bold text, click Format > Font, and then in the Find Font dialog box, select Bold in the Font style list.
Click the Replace with box, click Format, and then select the replacement formats.

NOTE: If you also want to replace the text, type the replacement text in the Replace with box.
To find and replace each instance of the specified formatting, click Find Next, and then click Replace. To replace all instances of the specified formatting, click Replace All.»

answered Nov 21, 2016 at 17:23

meatspace's user avatar

meatspacemeatspace

85916 silver badges25 bronze badges

1

In this article, we want to show you 2 quick and easy to use methods to extract texts from text boxes in your Word document.

From time to time, we can get a Word file containing a large number of text boxes. Usually, there will be texts or relative contents inside those boxes. Then there can be the need to get only the texts inside instead of keeping the whole text box.

Certainly, it’s quick to retrieve words within one single text box simply by copying the text out and pasting it somewhere else. However, when it comes to hundreds of them, we’d better learn some quick tips to get the job done.

Method 1: Use the “Selection Pane”

  1. First and foremost, click “Home” tab.
  2. Then click “Select” icon in “Editing” group.
  3. Next, on the drop-down menu, choose “Selection Pane”.Click "Home"->Click "Select"->Click "Selection Pane"
  4. Now on the right side of the screen, you can see all text boxes visible on the pane.
  5. Press “Ctrl” and click those text box names on the pane one by one to select them all.
  6. And move to lay cursor on one of the box line and right click.
  7. On the list-option, click “Copy”. Now if you won’t need those boxes anymore, just press “Delete”.Select All Text Boxes ->Right Click on One of the Box Line ->Choose "Copy"
  8. Next click “Start” to view the Windows menu.
  9. Choose “WordPad” and open it.Click "Start" ->Click "WordPad"
  10. Then click “Paste” to get all texts from the text boxes.Click "Paste"
  11. Next, select all texts and right click to choose “Copy”.Click "Copy"
  12. Now open a new Word document and right click to choose “Keep Text Only” to get the text.Right Click on the New Document ->Choose "Keep Text Only"

Method 2: Use VBA Codes

As you may see, even with the first method, you can’t avoid selecting all text boxes. In case some of you just hate such labor work, here we are to offer you the way to run a macro. With method 2, you can extract all texts in one go and have the text boxes deleted.

  1. Firstly, press “Alt+ F11” to open the VBA editor.
  2. Secondly, click “Normal” and then “Insert”.
  3. Next choose “Module” to insert a new one.Click "Normal"->Click "Insert"->Click "Module"
  4. Then double click on the module name to open the editing area.
  5. Paste the following codes and click “Run”:Paste Codes->Click "Run"
Sub DeleteTextBoxesAndExtractTheText()
  Dim nNumber As Integer
  Dim strText As String

  '  Delete all textboxes and extract the text from them
  With ActiveDocument
    For nNumber = .Shapes.Count To 1 Step -1
    If .Shapes(nNumber).Type = msoTextBox Then
      strText=strText& .Shapes(nNumber).TextFrame.TextRange.Text & vbCr
      .Shapes(nNumber).Delete
    End If
  Next
  End With

  '  Open a new document to paste the text from textboxes.
  If strText <> "" Then
    Documents.Add Template:="Normal"
    ActiveDocument.Range.Text = strText
  Else
    MsgBox ("There is no textbox.")
  End If
End Sub

Here is what you are likely to get:Effect of Running a Macro

Cope with Wrecked Word Files

Word is prone to errors and hence a frequent victim to corruption. Therefore, you have to manage your documents properly to protect them from damage. For once they getting corrupted, you will face the risk of losing them permanently. Then you will have to use the corrupted Word data recovery tool.

Author Introduction:

Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including Excel file error recovery tool and pdf repair software products. For more information visit www.datanumen.com

  • Remove From My Forums
  • Question

  • Hi everyone.

    i want to get all words in a Word Document and List all by ascending order then check the words finally replace wrong word with correct word…

    can everyone help me… solutions…suggestions…?

    • Moved by

      Sunday, January 23, 2011 6:21 AM
      Word, not VSTO-specific (From:Visual Studio Tools for Office)

Answers

  • Use:

    Sub WordFrequency()
             Dim SingleWord As String           ‘Raw word pulled from doc
            Const maxwords = 9000              ‘Maximum unique words allowed
            Dim Words(maxwords) As String      ‘Array to hold unique words
            Dim Freq(maxwords) As Integer      ‘Frequency counter for Unique Words
            Dim WordNum As Integer             ‘Number of unique words
            Dim ByFreq As Boolean              ‘Flag for sorting order
            Dim ttlwds As Long                 ‘Total words in the document
            Dim Excludes As String             ‘Words to be excluded
            Dim Found As Boolean               ‘Temporary flag
            Dim j, k, l, Temp As Integer       ‘Temporary variables
            Dim tword As String                ‘
             ‘ Set up excluded words
    ‘         Excludes = «[the][a][of][is][to][for][this][that][by][be][and][are]»
            Excludes = «»
            Excludes = InputBox$(«Enter words that you wish to exclude, surrounding each word with [ ].», «Excluded Words», «»)
    ‘        Excludes = Excludes & InputBox$(«The following words are excluded: » & Excludes & «. Enter words that you wish to exclude, surrounding each word with [ ].», «Excluded Words», «»)
    ‘ Find out how to sort
    ByFreq = True
    Ans = InputBox$(«Sort by WORD or by FREQ?», «Sort order», «FREQ»)
    If Ans = «» Then End
    If UCase(Ans) = «WORD» Then
       ByFreq = False
    End If
    Selection.HomeKey Unit:=wdStory
    System.Cursor = wdCursorWait
    WordNum = 0
    ttlwds = ActiveDocument.Words.Count
    Totalwords = ActiveDocument.BuiltInDocumentProperties(wdPropertyWords)
            ‘ Control the repeat
            For Each aword In ActiveDocument.Words
                SingleWord = Trim(aword)
                If SingleWord < «A» Or SingleWord > «z» Then SingleWord = «» ‘Out of range?
                If InStr(Excludes, «[» & SingleWord & «]») Then SingleWord = «» ‘On exclude list?
                If Len(SingleWord) > 0 Then
                    Found = False
                    For j = 1 To WordNum
                        If Words(j) = SingleWord Then
                            Freq(j) = Freq(j) + 1
                            Found = True
                            Exit For
                        End If
                    Next j
                    If Not Found Then
                        WordNum = WordNum + 1
                        Words(WordNum) = SingleWord
                        Freq(WordNum) = 1
                    End If
                    If WordNum > maxwords — 1 Then
                        j = MsgBox(«The maximum array size has been exceeded. Increase maxwords.», vbOKOnly)
                        Exit For
                    End If
                End If
                ttlwds = ttlwds — 1
                StatusBar = «Remaining: » & ttlwds & »     Unique: » & WordNum
            Next aword
             ‘ Now sort it into word order
            For j = 1 To WordNum — 1
                k = j
                For l = j + 1 To WordNum
                    If (Not ByFreq And Words(l) < Words(k)) Or (ByFreq And Freq(l) > Freq(k)) Then k = l
                Next l
                If k <> j Then
                    tword = Words(j)
                    Words(j) = Words(k)
                    Words(k) = tword
                    Temp = Freq(j)
                    Freq(j) = Freq(k)
                    Freq(k) = Temp
                End If
                StatusBar = «Sorting: » & WordNum — j
            Next j
             ‘ Now write out the results
            tmpName = ActiveDocument.AttachedTemplate.FullName
            Documents.Add Template:=tmpName, NewTemplate:=False
            Selection.ParagraphFormat.TabStops.ClearAll
            With Selection
                For j = 1 To WordNum
                    .TypeText Text:=Words(j) & vbTab & Trim(Str(Freq(j))) & vbCrLf
                Next j
            End With
            ActiveDocument.Range.Select
            Selection.ConvertToTable
            Selection.Collapse wdCollapseStart
            ActiveDocument.Tables(1).Rows.Add BeforeRow:=Selection.Rows(1)
            ActiveDocument.Tables(1).Cell(1, 1).Range.InsertBefore «Word»
            ActiveDocument.Tables(1).Cell(1, 2).Range.InsertBefore «Occurrences»
            ActiveDocument.Tables(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
            ActiveDocument.Tables(1).Rows.Add
            ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count, 1).Range.InsertBefore «Total words in Document»
            ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count, 2).Range.InsertBefore Totalwords
            ActiveDocument.Tables(1).Rows.Add
            ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count, 1).Range.InsertBefore «Number of different words in Document»
            ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count, 2).Range.InsertBefore Trim(Str(WordNum))
            System.Cursor = wdCursorNormal
            j = MsgBox(«There were » & Trim(Str(WordNum)) & » different words «, vbOKOnly, «Finished»)
        Selection.HomeKey wdStory

    End Sub
     — Hope this helps.

    Doug Robbins — Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    «Adnan Ebrahimi» wrote in message news:8ddb02da-d954-40f4-b4a5-403fa8fa5a69@communitybridge.codeplex.com…

    Hi everyone.

    i want to get all words in a Word Document and List all by ascending order then check the words finally replace wrong word with correct word…

    can everyone help me… solutions…suggestions…?


    Doug Robbins — Word MVP dkr[atsymbol]mvps[dot]org

    • Marked as answer by
      Bessie Zhao
      Monday, February 7, 2011 10:02 AM

  • Hi Abdan

    If you’re working with the Word object model, going through the .NET/COM, Word OLE interface, and given the speed of processing in that interface, I don’t think you can get anything faster than what you’ve got. It’s the nature of the thing you’re doing.

    Possibly, if the file is in the Office 2007/2010 Open XML file format (docx, for example) you can work with that file as you would any XML file. But we can’t help you here with that. You’ll find more information on Open XML file format at openXMLDeveloper.org


    Cindy Meister, VSTO/Word MVP

    • Marked as answer by
      Bessie Zhao
      Monday, February 7, 2011 10:02 AM

Old

02-03-2019, 07:42 AM

Novice

How to get all headers text in a Word Document ?

 

Join Date: Feb 2019

Posts: 22

BeginnerLearner is on a distinguished road

Default

How to get all headers text in a Word Document ?


Hi,

I have a Word Document.

Every page has a header.

Right now I am only able to get the current page header.

Eg. If the page is currently at page 3, it will only display page 3 header text in a MessageBox.

The attached image is what I have tried.
I was thinking is it I have to use a For loop to get all pages’ header text?

Thank you

Reply With Quote

Old

02-03-2019, 08:06 AM

Default


There are potentially three headers in each section of the document. Your macro accesses one of them. If you want them all you need to loop through the sections and the headers in those sections e.g.

Code:

Dim oSection As Section
Dim oHeader As HeaderFooter
    For Each oSection In ActiveDocument.Sections
        For Each oHeader In oSection.Headers
            If oHeader.Exists Then
                MsgBox oHeader.Range.Text
            End If
        Next oHeader
    Next oSection

__________________
Graham Mayor — MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com

Reply With Quote

Old

02-03-2019, 08:51 AM

Novice

How to get all headers text in a Word Document ?

 

Join Date: Feb 2019

Posts: 22

BeginnerLearner is on a distinguished road

Default


Hi, gmayor

I have tried the given codes.
However, it still displays only one of the pages header text.

The first MessageBox displays one of the pages header text.
When I clicked ‘Ok’, the second MessageBox displays nothing and then it ends.

I used

Code:

MsgBox ActiveDocument.Sections.Count

to check the number of sections and it displays 1

May I know what could be the reason? May I know why does the Word Document only have 1 section?

Thank you


Last edited by BeginnerLearner; 02-03-2019 at 06:09 PM.

Reply With Quote

Old

02-03-2019, 07:49 PM

gmaxey
gmaxey is offline

How to get all headers text in a Word Document ? Windows 10 How to get all headers text in a Word Document ? Office 2016

Word MVP 2003-2009

 

Join Date: May 2010

Location: Brasstown, NC

Posts: 1,250

gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough

Default


One section or one hundred, each section has 3 headers (used or not).

Code:

Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 02/03/2019
Dim lngIndex As Long
Dim oSec As Section
  For Each oSec In ActiveDocument.Sections
    For lngIndex = 1 To 3
      MsgBox oSec.Headers(lngIndex).Range.Text
    Next
  Next
lbl_Exit:
  Exit Sub
End Sub

Reply With Quote

Old

02-03-2019, 08:16 PM

Novice

How to get all headers text in a Word Document ?

 

Join Date: Feb 2019

Posts: 22

BeginnerLearner is on a distinguished road

Default


Hi, gmayor

lngIndex means that it is going through the 3 headers for each section, that why you put 1 To 3?

I have tried the above code and it still the same.
The first MessageBox displays the header text.
The second and third MessageBox display empty.

Thank you

Reply With Quote

Old

02-03-2019, 10:04 PM

Default


Post the document so we can view it. The macro which Greg posted is just a variation of what I posted and either will show the text content of the headers in each section.

If your macro shows only one section then there is only one section in the document. This should be confirmed by the Word status bar (right click the status bar and ensure that Sections is checked).

__________________
Graham Mayor — MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com

Reply With Quote

Old

02-04-2019, 10:20 AM

Novice

How to get all headers text in a Word Document ?

 

Join Date: Feb 2019

Posts: 22

BeginnerLearner is on a distinguished road

Default


Hi, gmayor

I have checked the Word status bar and it only shows 1.

Attached is a sample Word Document.

There are 3 pages and each page has a header.
I want to get all header.

However currently, I am only able to get one of the header text.

May I know what is the reason?

Thank you

Reply With Quote

Old

02-04-2019, 11:56 AM

gmaxey
gmaxey is offline

How to get all headers text in a Word Document ? Windows 10 How to get all headers text in a Word Document ? Office 2016

Word MVP 2003-2009

 

Join Date: May 2010

Location: Brasstown, NC

Posts: 1,250

gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough

Default


My name is not gmayor. gmayor is the other person helping you.

Every section of a document has three headers 1) FirstPageHeader 2) PrimaryPageHeader and 3) EvenPageHeader. Your document has 1 section and that section is formatted with primary page header only. If you want to use all three headers then you need to format the page layout for different odd and even pages and different first page.

Note: Even then you are only going to get three message boxes regardless if your 1 section document has one page or a thousand pages.

Reply With Quote

Old

02-04-2019, 09:29 PM

Default


Your sample document has one section and uses ony the primary header which repeats on all three pages. That header contains a field that reflects the page number it appears on.
The macro I posted will display a single message showing that header, however as fields are not compatible with text displays that message will show Page 1.

__________________
Graham Mayor — MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com

Reply With Quote

Old

02-05-2019, 03:58 PM

Default


Every section contains three different headers and three different footers.

BUT you won’t necessarily SEE them in your document unless:
— Page Setup > Layout > Different odd and even is TURNED ON
— Page Setup > Layout > Different first page is TURNED ON
— and your section contains at least 3 pages

If any of those are not true, then you won’t be able to see the header or footer but it will still exist. Your sample document contains three pages but it has both the page setup layout options turned off. The VBA is reporting on two things you can’t see — and the three pages you can see are all showing the same header/footer.

__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Reply With Quote

Old

02-06-2019, 09:54 AM

Novice

How to get all headers text in a Word Document ?

 

Join Date: Feb 2019

Posts: 22

BeginnerLearner is on a distinguished road

Default


Hi, gmaxey

Sorry as both name look familiar thus I thought is gmayor

Does that mean if I want to get all header, I have to find using

Code:

wdHeaderFooterPrimaryPages

?

Thank you

Reply With Quote

Old

02-06-2019, 10:00 AM

Novice

How to get all headers text in a Word Document ?

 

Join Date: Feb 2019

Posts: 22

BeginnerLearner is on a distinguished road

Default


Hi gmayor

As my sample document uses only primary pages
Does that mean in a For Loop, If header exists, I have to check if the header is PrimaryPageHeader before displaying in a MsgBox?

Thank you

Reply With Quote

Old

02-06-2019, 10:10 AM

Novice

How to get all headers text in a Word Document ?

 

Join Date: Feb 2019

Posts: 22

BeginnerLearner is on a distinguished road

Default


Hi, Guessed

Thanks for your help!

As my sample document uses only primary pages

If both the page setup layout options are turned off, will it affect anything or the outcome?

Thank you

Reply With Quote

Old

02-06-2019, 01:11 PM

Default


Obviously, if your document doesn’t have a ‘different first page’ or ‘different odd and even’ page setup, you won’t get any output for the corresponding headers.

__________________
Cheers,
Paul Edstein
[Fmr MS MVP — Word]

Reply With Quote

Old

02-06-2019, 03:03 PM

Default


«the outcome» is an interesting term. We don’t actually know what it is that you are trying to do. The information you have seen from me, Greg, Graham and Paul is all correct but perhaps not fulfilling what you really want because you haven’t been clear on that.

Displaying a messagebox of the text string of a header is pretty pointless — it doesn’t show formatting, graphics, tables, fields etc. If you can explain what exactly you want to do with the header content, perhaps we can tell you what you actually need to know.

__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Reply With Quote

Понравилась статья? Поделить с друзьями:
  • Word germany come from
  • Word generator with the letters
  • Word generator with letter
  • Word generator with given words
  • Word generator using two words