Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 02-06-2019, 05:34 PM
BeginnerLearner BeginnerLearner 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 2013
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

My header text contains the exam title, the exam module code, and the page number.
After getting all header text, I wanted to check if the exam title and module code are correct based on the exam cover page. I also wanted to check if the page number has a number in it.

Thank you
Reply With Quote
  #17  
Old 02-06-2019, 05:54 PM
macropod's Avatar
macropod macropod is offline How to get all headers text in a Word Document ? Windows 7 64bit How to get all headers text in a Word Document ? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your attachment in Post #7 doesn't show how the cover page might relate to anything in the page header, so it's difficult to code for that. That said, if you want to ensure the exam title and module code are correct there, all you need do is assign specific Styles to your the exam title and module code are correct, then use STYLEREF fields in the page header to replicate them. That way, you don't need any code to test whether they're the same. See attached. Anything you type in the second column on the table will be replicated - as you type - in the page header.
Attached Files
File Type: docx Test_Practice.docx (16.1 KB, 12 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #18  
Old 02-06-2019, 09:23 PM
BeginnerLearner BeginnerLearner 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 2013
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, macropod

I am using UiPath to open the Word Document and run the macro.
Attached is an image(image_1).

However, If I change the file path, the exam title and module code will be different as it is from another document.

Hence I think the suggestion you gave may not be suitable for me.

I have attached another sample word document. The first page(cover page) contains the exam title and module code. I want to check if all header text's exam title and module code is correct based on the cover page. I also want to check if the page number has a number in it.

Thank you
Attached Images
File Type: png image_1.PNG (17.1 KB, 24 views)
Attached Files
File Type: docx Test_Practice.docx (16.7 KB, 9 views)
Reply With Quote
  #19  
Old 02-06-2019, 09:43 PM
macropod's Avatar
macropod macropod is offline How to get all headers text in a Word Document ? Windows 7 64bit How to get all headers text in a Word Document ? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

There is nothing about your latest attachment that precludes the approach I suggested. Using a table as I have done makes it easier to manage but, provided you apply the appropriate Styles to your exam title and module code, the STYLEREF fields will work just the same. Changing the file path isn't at all relevant.

As for the document itself, what you've been telling us until now suggested that your document's page setup was one where "both the page setup layout options are turned off", meaning it only had a primary header. Your latest attachment has a 'different first page' setup.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #20  
Old 02-06-2019, 11:07 PM
BeginnerLearner BeginnerLearner 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 2013
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, macropod

Sorry my mistake, my actual document has a 'different first page' setup.

Does that mean I have to do the table manually, every time I open a word document?

If I want to use macro, is there a way to retrieve all header and check?

Sorry that I ask too many questions

Thank you
Reply With Quote
  #21  
Old 02-07-2019, 12:20 AM
macropod's Avatar
macropod macropod is offline How to get all headers text in a Word Document ? Windows 7 64bit How to get all headers text in a Word Document ? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by BeginnerLearner View Post
my actual document has a 'different first page' setup.

Does that mean I have to do the table manually, every time I open a word document?
No, it doesn't mean that.
Quote:
Originally Posted by BeginnerLearner View Post
If I want to use macro, is there a way to retrieve all header and check?
The problem you have with doing a check has more to do with the fact your cover page doesn't say the same thing as your header even in the example you gave. Whilst a human can see the header is consistent with the cover page, having a macro recognise that when they're not exactly the same is problematic at best.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #22  
Old 02-07-2019, 12:38 AM
BeginnerLearner BeginnerLearner 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 2013
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, macropod

So if the header and cover page are not exactly the same, it is hard to use VBA to check?

Eg. The header text: Mathematics Exam
The cover page: Mathematics Examination

Thank you
Reply With Quote
  #23  
Old 02-07-2019, 04:35 AM
macropod's Avatar
macropod macropod is offline How to get all headers text in a Word Document ? Windows 7 64bit How to get all headers text in a Word Document ? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Well, if they're not the same, they're not the same. In your example document, they're not the same for either line:
2016/2017 Mid-Term Examination
is not the same as:
Mid-Term Exam
and:
Module : A123 – Mathematics
is not the same as:
A123

Sure VBA code could be written to handle those particular cases, but that becomes a nightmare as the number of cases to be dealt with increases. And, even then, it all breaks down once people start deviating from what's been coded for. Even something as simple as one person using:
Mid-Term Exam
another using:
Mid Term Exam
and yet another using:
Midterm Exam
would trip it up.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #24  
Old 02-07-2019, 07:35 AM
BeginnerLearner BeginnerLearner 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 2013
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, macropod

Thank you for your explanation, now I get it

Sorry I have last 2 questions.

What if instead of checking if the words are exactly the same, we check if the words are similar? Will this cause a problem?

Instead of using sections, can I check page by page?

Thank you
Reply With Quote
  #25  
Old 02-07-2019, 01:08 PM
macropod's Avatar
macropod macropod is offline How to get all headers text in a Word Document ? Windows 7 64bit How to get all headers text in a Word Document ? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by BeginnerLearner View Post
What if instead of checking if the words are exactly the same, we check if the words are similar? Will this cause a problem?
It's exactly the same problem.

Quote:
Originally Posted by BeginnerLearner View Post
Instead of using sections, can I check page by page?
I can't see what Sections has to do with this - your example document still only has one Section. Regardless, for a multi-Section document, all you'd be doing is repeating the same comparison issue for every Section.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #26  
Old 02-08-2019, 12:47 AM
BeginnerLearner BeginnerLearner 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 2013
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, macropod

Do you know other ways to get all headers from the word document?

At first, I wanted to go through the word document using page by page. However, I have searched online and found out that I can't do that as Word is not a page layout software.

I have also tried using StoryRanges.

Code:
Sub getHeader()

Dim oStory As Range
MakeHValid
For Each oStory In ActiveDocument.StoryRanges
    Do
        If oStory.StoryType = wdPrimaryHeaderStory Then
            MsgBox "There is a header"
            MsgBox oStory
        End If
        Get next linked story
        Set oStory = oStory.NextStoryRange
        Loop Until oStory Is Nothing
        Next

End Sub

Public Sub MakeHValid()
Dim lngjunk As Long
lngjunk = ActiveDocument.Range.StoryType
End Sub
Code:
MsgBox ActiveDocument.StoryRanges(wdPrimaryHeaderStory)
However, it did not work. The second code only gives me one of the headers text.

Thus, I am thinking if there is any way to get all the headers.

Thank you for your help
Reply With Quote
  #27  
Old 02-08-2019, 01:31 AM
Guessed's Avatar
Guessed Guessed 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
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I still don't see the point of 'getting all the headers'. What are you going to do once you 'get them'? The text content of the header range is not particularly useful. It doesn't show the layout such as tables or graphics.

If you want a macro to ensure all the headers in the document contain the desired content then there is no need to find out what is already there - simply replace the headers with your desired content.

There are other things besides headers to worry about if you are trying to standardise page furniture content such as page setups for each section. You can store all these things in a section break saved as a building block. Then you can standardise the doc by using a macro that removes section breaks and then adds the building block to the end of the document. If you then copy the relevant settings to the final section you can then remove the section break.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #28  
Old 02-08-2019, 02:04 AM
BeginnerLearner BeginnerLearner 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 2013
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

I am doing a program using UiPath to check for errors in the exam paper(which is the word document).

Right now I am trying to check if the header text in the exam paper is equal to the cover page title and module code. Thus, I want to get all the header text to ensure all header text is correct.

Thank you
Reply With Quote
  #29  
Old 02-08-2019, 03:51 AM
macropod's Avatar
macropod macropod is offline How to get all headers text in a Word Document ? Windows 7 64bit How to get all headers text in a Word Document ? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You don't seem to be paying attention!!! Getting the headers isn't going to help you because they're not directly comparable with your cover pages. Furthermore, I've already told you how you can obviate the problem - if you're willing to learn.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #30  
Old 02-08-2019, 09:42 AM
BeginnerLearner BeginnerLearner 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 2013
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, macropod

I am really sorry, but I am confused about the suggestion you gave in Post #17.

Does it mean every time I run the program to check the document, I have to assign specific styles to the exam title and module code manually? Am I able to save the assigned style? so that any document I open will already have the assigned style.

Thank you
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apply template with headers/footers to an existing Word document Files qadeerahmed Word 5 05-08-2017 05:28 AM
Headers & Footers - Show Document Text Aprilann Word 6 04-13-2017 09:34 AM
How to get all headers text in a Word Document ? Word 2007 - different text for odd and even headers? JQP Word 4 10-09-2011 06:49 PM
How do I have headers and footers appear as regular text for the whole document? user908045 Word 0 03-13-2010 12:41 PM
Portrait & Landscape Headers in Same Word Document Coast331 Word 0 10-24-2009 02:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:25 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft