Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Replace left header

I have a left header in all my project documents. What I want is macro
code that if the header has two lines, exit the macro, no change. If
however it has only one line, I want it to keep that line and add
another line with Range("A2") value. Any help appreciated. TIA

Greg

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Replace left header

Option Explicit

Sub LeftHeader()

Dim strLeftHeader As String
Dim strTemp As String

strLeftHeader = ActiveSheet.PageSetup.LeftHeader

' If header contains Chr(10), there is more than one line in header
strTemp = Replace(strLeftHeader, Chr(10), "", 1, -1)

If Len(strTemp) = Len(strLeftHeader) Then
ActiveSheet.PageSetup.LeftHeader = strLeftHeader & Chr(10) _
& Range("A2").Value
End If

End Sub


Mark


GregR wrote:
I have a left header in all my project documents. What I want is macro
code that if the header has two lines, exit the macro, no change. If
however it has only one line, I want it to keep that line and add
another line with Range("A2") value. Any help appreciated. TIA

Greg


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Replace left header

Mark, thank you very much, exactly what I wanted

Greg
Mark Driscol wrote:
Option Explicit

Sub LeftHeader()

Dim strLeftHeader As String
Dim strTemp As String

strLeftHeader = ActiveSheet.PageSetup.LeftHeader

' If header contains Chr(10), there is more than one line in header
strTemp = Replace(strLeftHeader, Chr(10), "", 1, -1)

If Len(strTemp) = Len(strLeftHeader) Then
ActiveSheet.PageSetup.LeftHeader = strLeftHeader & Chr(10) _
& Range("A2").Value
End If

End Sub


Mark


GregR wrote:
I have a left header in all my project documents. What I want is macro
code that if the header has two lines, exit the macro, no change. If
however it has only one line, I want it to keep that line and add
another line with Range("A2") value. Any help appreciated. TIA

Greg


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Only change left header on all worksheets RobinK Excel Discussion (Misc queries) 0 February 22nd 08 06:13 PM
How do I left justify center section header nick Excel Discussion (Misc queries) 1 September 6th 06 09:30 PM
header in right or left margin? Michelle Excel Discussion (Misc queries) 2 January 26th 05 04:44 PM
Left/Right Margins in Header/Footer BobB Excel Discussion (Misc queries) 1 November 29th 04 09:04 PM
Header/Left margin PO Excel Programming 2 August 30th 04 06:31 PM


All times are GMT +1. The time now is 05:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"