Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-26-2020, 02:02 PM
RAFCRIK RAFCRIK is offline Use StyleRef based on previous page - IF this-and-that Windows 10 Use StyleRef based on previous page - IF this-and-that Office 2016
Novice
Use StyleRef based on previous page - IF this-and-that
 
Join Date: Aug 2020
Posts: 6
RAFCRIK is on a distinguished road
Default Use StyleRef based on previous page - IF this-and-that

Hello,

My apologies in advance for being yet another noob who abuses this forum for his own problems... I really have practically no knowledge of Visual Basic or the "Fields" of Word. But I do have a project in which they (hopefully) offer the grail to my quest.

Here are the variables of what I want to achieve:
  • I only need it in the header of certain (luckily succeeding each other) sections (so maybe using placeholders like Ł and µ might help?)
  • If the first line of the page is in style "Kop 1;REGEL;Rule" OR in style "Kop 2;SECTIE;Section":
    Ł should be { STYLEREF "Kop 2;SECTIE;Section" \n \t \* MERGEFORMAT }.
    µ should be { STYLEREF "Kop 2;SECTIE;Section" \* MERGEFORMAT }.
  • If the first line of the page is in neither style "Kop 1;REGEL;Rule" nor "Kop 2;SECTIE;Section":
    Ł should be { STYLEREF "Kop 2;SECTIE;Section" \l \n \t \* MERGEFORMAT } of the previous page.
    µ should be { STYLEREF "Kop 2;SECTIE;Section" \l \* MERGEFORMAT } of the previous page.
In essence, it's a header like in a dictionary: not the next "title", but the one to which the first line of the page belongs.

Do you see any possibility to make this magic happen?



Thanks in advance for your help!
Reply With Quote
  #2  
Old 08-26-2020, 07:55 PM
Charles Kenyon Charles Kenyon is offline Use StyleRef based on previous page - IF this-and-that Windows 10 Use StyleRef based on previous page - IF this-and-that Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 7,667
Charles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud of
Default

Take a look at Useful StyleRef tricks by Suzanne Barnhill, MVP. It should give you a start with using the StyleRef Field. The StyleRef field is one of the underutilized tools provided by Word.


I would recommend getting rid of all of the \* MERGEFORMAT switches.

I know of no way of ignoring a target style on the same page as the header when it is not in the first line.

You might want to start using Page Break Before formatting for that style so it will always be the first line of a page.
Reply With Quote
  #3  
Old 09-29-2020, 12:53 AM
RAFCRIK RAFCRIK is offline Use StyleRef based on previous page - IF this-and-that Windows 10 Use StyleRef based on previous page - IF this-and-that Office 2016
Novice
Use StyleRef based on previous page - IF this-and-that
 
Join Date: Aug 2020
Posts: 6
RAFCRIK is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
You might want to start using Page Break Before formatting for that style so it will always be the first line of a page.
No, that's not the result I'm looking for. I want the header to reflect the number of the chapter to which the first line of the page belongs to.
Unless that first line is in itself a heading 1 or 2 (which means the first line of "real" text belongs to the chapter of said heading).

Actually there are a couple of things I would want to combine. For that to work, they must of course be possible on their own...
  1. Is it possible to create some kind of "IF" formula in which the criterion is that the first line of a page is in a certain style?
  2. Is it possible to somehow (maybe using Visual Basic?) get {STYLEREF "Kop 1;REGEL;Rule" \n \t} of "PAGE -1"?
  3. If #2 is possible, is it possible to run this "formula" on every instance of e.g. "$". A "replace all" if you will.
Reply With Quote
  #4  
Old 10-31-2020, 09:11 AM
RAFCRIK RAFCRIK is offline Use StyleRef based on previous page - IF this-and-that Windows 10 Use StyleRef based on previous page - IF this-and-that Office 2016
Novice
Use StyleRef based on previous page - IF this-and-that
 
Join Date: Aug 2020
Posts: 6
RAFCRIK is on a distinguished road
Default

Impossible?
Reply With Quote
  #5  
Old 10-31-2020, 11:38 AM
Charles Kenyon Charles Kenyon is offline Use StyleRef based on previous page - IF this-and-that Windows 10 Use StyleRef based on previous page - IF this-and-that Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 7,667
Charles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud of
Default

Quote:
Originally Posted by RAFCRIK View Post
Impossible?
Did you look at Suzanne's page?

Be patient. This is a user-to-user support forum with no connection to Microsoft. Others may weigh in.
Reply With Quote
  #6  
Old 10-12-2021, 07:00 PM
amenoire amenoire is offline Use StyleRef based on previous page - IF this-and-that Windows 10 Use StyleRef based on previous page - IF this-and-that Office 2019
Novice
 
Join Date: Oct 2021
Posts: 1
amenoire is on a distinguished road
Default

Hey RAFCRIK,

I came upon this thread also looking for an answer to this kind of problem, and in the mean-time have happened upon a solution. I know it's been a while since you asked, but if it's not helpful for you hopefully it will be to somebody else.


Background:
In my document's header, I am using {styleref} fields to print '{Heading 1}: {Heading 2}'. I also wanted this to display heading information for the text at the top of the page, but this was problematic for me because the heading text was generally on the previous page. Fortunately, the style of my document was similar to that which Charles had suggested above, and for the 'Heading 1' style, each was preceded by a page break. The trouble I had was specifically with 'Heading 2'.

On each page where there is no new text in the 'Heading 1' or 'Heading 2' styles, Word will search back up the document (like we want it to!), finding the previous instance and referencing that. For me, this meant the field {Heading 1} was always correct, but {Heading 2} was incorrect, unless it happened to begin at the top of the page.


Solution:
Immediately before every new 'Heading 2' style, I added a {Heading 2} field, and then applied the 'Heading 2' style to it. Word searches the current page (importantly: above the field) for the 'Heading 2' style. Because it doesn't appear on this page yet (remember: this is before the next 'Heading 2' instance), Word keeps searching up to the previous page, finding the last instance of 'Heading 2' on the previous page (or, presumably, earlier? This was not an issue for me as I have level two headings on every page, just not always at the start of the page).

Once the preceding heading is in place, you want to make it 'invisible'. Because you can't use the 'hidden' text feature, I simply changed the font size to 1, and font colour to white. To keep consistency in formatting, I have inserted this tiny white text above all of my headings that aren't at the top of the next page (this ensures there's not a spacing difference).

Hope this helps!


Examples:
Imagine the text at the top of my page belongs to a heading called 'Heading 1.1' So at the top of my page I want it to show that. Below that text, Heading 1.2 begins, however, so the header is instead referencing that text.

At the beginning, my page initially looks like this...

------- top of page -------

HEADING 1.2 {‘Heading 1’}

------ end of header ------

amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

HEADING 1.2
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

------- end of page -------


Note: The {} after text indicate that text has been called by the field.


After step one, my page now looks like this...

------- top of page -------

HEADING 1.1 {‘Heading 1’}

------ end of header ------

amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

HEADING 1.1 {‘Heading 1’}
HEADING 1.2
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

------- end of page -------



After step two, my page now looks like this... (On a white background, you can't see the heading text)

------- top of page -------

HEADING 1.1 {‘Heading 1’}

------ end of header ------

amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

HEADING 1.1 {‘Heading 1’}
HEADING 1.2
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

------- end of page -------
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto fill based on previous entry geojf3 Word VBA 6 11-25-2019 06:49 AM
Start page numbering on second page ("link to previous" is greyed-out) seanspotatobusiness Word 1 07-11-2018 10:33 AM
Use StyleRef based on previous page - IF this-and-that Table on top of page breaks the paragraph on previous page iffee82 Word Tables 18 05-10-2018 02:44 AM
Use StyleRef based on previous page - IF this-and-that Table adding cells to previous page with room still on current page. gedet Word 1 01-03-2018 10:35 AM
Use StyleRef based on previous page - IF this-and-that MS Word, page goes to next page when entering data on previous page munna94 Word 2 12-30-2010 08:12 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:25 AM.


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