A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Help changing a style of a field in a header or footer



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old August 21st 08, 08:46 PM posted to microsoft.public.outlook.program_vba
SWT
external usenet poster
 
Posts: 5
Default Help changing a style of a field in a header or footer

I am having trouble changing the style of a field in the header/footer
without it affecting the style of the text that was already in the
header/footer.

When I insert the field before the existing text, the style changes
perfectly fine...

range = section.Headers(wdHeaderFooterPrimary).range
range.InsertBefore("IF PAGE = NUMPAGES ""Hello World" & vbcrlf & """)
range.SetRange(rangeEndBeforeInsert, range.End)
range.Fields.Add(range, wdFieldEmpty, , False)
range.SetRange(rangeEndBeforeInsert, range.End)
range.Style = word.ActiveDocument.Styles("Style")

However, when I insert the field at the end of the range, set the range's
boundaries to the field, and change the style, it also changes the style of
the text at the beginning of the header/footer...

range = section.Headers(wdHeaderFooterPrimary).range
range.InsertAfter("IF PAGE = NUMPAGES """ & vbcrlf & "Hello World""")
range.SetRange(rangeEndBeforeInsert, range.End)
range.Fields.Add(range, wdFieldEmpty, , False)
range.SetRange(rangeEndBeforeInsert, range.End)
range.Style = word.ActiveDocument.Styles("Style")

Again, the code works perfectly fine for the InsertBefore, it's just when I
insert the code after and I try to change the style, the text before the
field is changed to that style too. I wrote the code here in VB, but it's the
same with VB.net and VBA.

Any suggestions?

Ads
  #2  
Old August 21st 08, 08:56 PM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Help changing a style of a field in a header or footer



Wouldn't that be a question to ask in a Word forum?

--
Best regards
Michael Bauer - MVP Outlook

: VBOffice Reporter for Data Analysis & Reporting
: Outlook Categories? Category Manager Is Your Tool
: http://www.vboffice.net/product.html?pub=6&lang=en


Am Thu, 21 Aug 2008 11:46:03 -0700 schrieb SWT:

I am having trouble changing the style of a field in the header/footer
without it affecting the style of the text that was already in the
header/footer.

When I insert the field before the existing text, the style changes
perfectly fine...

range = section.Headers(wdHeaderFooterPrimary).range
range.InsertBefore("IF PAGE = NUMPAGES ""Hello World" & vbcrlf & """)
range.SetRange(rangeEndBeforeInsert, range.End)
range.Fields.Add(range, wdFieldEmpty, , False)
range.SetRange(rangeEndBeforeInsert, range.End)
range.Style = word.ActiveDocument.Styles("Style")

However, when I insert the field at the end of the range, set the range's
boundaries to the field, and change the style, it also changes the style

of
the text at the beginning of the header/footer...

range = section.Headers(wdHeaderFooterPrimary).range
range.InsertAfter("IF PAGE = NUMPAGES """ & vbcrlf & "Hello World""")
range.SetRange(rangeEndBeforeInsert, range.End)
range.Fields.Add(range, wdFieldEmpty, , False)
range.SetRange(rangeEndBeforeInsert, range.End)
range.Style = word.ActiveDocument.Styles("Style")

Again, the code works perfectly fine for the InsertBefore, it's just when

I
insert the code after and I try to change the style, the text before the
field is changed to that style too. I wrote the code here in VB, but it's

the
same with VB.net and VBA.

Any suggestions?

  #3  
Old August 21st 08, 09:10 PM posted to microsoft.public.outlook.program_vba
SWT
external usenet poster
 
Posts: 5
Default Help changing a style of a field in a header or footer

Yep, I caught that after I posted it. Sorry for the confusion.

"Michael Bauer [MVP - Outlook]" wrote:



Wouldn't that be a question to ask in a Word forum?

--
Best regards
Michael Bauer - MVP Outlook

: VBOffice Reporter for Data Analysis & Reporting
: Outlook Categories? Category Manager Is Your Tool
: http://www.vboffice.net/product.html?pub=6&lang=en


Am Thu, 21 Aug 2008 11:46:03 -0700 schrieb SWT:

I am having trouble changing the style of a field in the header/footer
without it affecting the style of the text that was already in the
header/footer.

When I insert the field before the existing text, the style changes
perfectly fine...

range = section.Headers(wdHeaderFooterPrimary).range
range.InsertBefore("IF PAGE = NUMPAGES ""Hello World" & vbcrlf & """)
range.SetRange(rangeEndBeforeInsert, range.End)
range.Fields.Add(range, wdFieldEmpty, , False)
range.SetRange(rangeEndBeforeInsert, range.End)
range.Style = word.ActiveDocument.Styles("Style")

However, when I insert the field at the end of the range, set the range's
boundaries to the field, and change the style, it also changes the style

of
the text at the beginning of the header/footer...

range = section.Headers(wdHeaderFooterPrimary).range
range.InsertAfter("IF PAGE = NUMPAGES """ & vbcrlf & "Hello World""")
range.SetRange(rangeEndBeforeInsert, range.End)
range.Fields.Add(range, wdFieldEmpty, , False)
range.SetRange(rangeEndBeforeInsert, range.End)
range.Style = word.ActiveDocument.Styles("Style")

Again, the code works perfectly fine for the InsertBefore, it's just when

I
insert the code after and I try to change the style, the text before the
field is changed to that style too. I wrote the code here in VB, but it's

the
same with VB.net and VBA.

Any suggestions?


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I print email without the date on the header and footer? win Outlook - General Queries 1 September 2nd 07 02:52 AM
Header & Footer David French Outlook - Calandaring 1 August 25th 06 06:45 PM
VBA code to populate an email header and footer marie Outlook and VBA 1 July 28th 06 04:21 AM
Word Reference header/footer files Mr. Esteban Outlook and VBA 1 May 27th 06 12:35 PM
Changing calendar header and or footer Denisa Outlook - Calandaring 0 May 10th 06 04:03 PM


All times are GMT +1. The time now is 08:26 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.