#16
|
|||
|
|||
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 |
#17
|
||||
|
||||
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.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#18
|
|||
|
|||
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 |
#19
|
||||
|
||||
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] |
#20
|
|||
|
|||
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 |
#21
|
||||
|
||||
Quote:
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] |
#22
|
|||
|
|||
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 |
#23
|
||||
|
||||
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] |
#24
|
|||
|
|||
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 |
#25
|
||||
|
||||
Quote:
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] |
#26
|
|||
|
|||
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) Thus, I am thinking if there is any way to get all the headers. Thank you for your help |
#27
|
||||
|
||||
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 |
#28
|
|||
|
|||
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 |
#29
|
||||
|
||||
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] |
#30
|
|||
|
|||
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 |
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 |
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 |