最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

vba - Is there a way to put the content of a referenced cell from a different sheet to be used as header in another sheet Micros

programmeradmin4浏览0评论

I've been pondering about this problem. To simply put, I want to automate making Executive Summary for our company. I want to add Right Header on pages 2 onwards while leaving the first page with blank header. The problem is, the text I want to use is a combination of text from different references. I did concatenate it into a single cell on another sheet and I want to use that cell as the reference for my header. Can someone help me on this. Thank you so much in advance.

I tried vba using this code

ActiveSheet.PageSetup.DifferentFirstPageHeaderFooter = True
ActiveSheet.PageSetup.RightHeader = "the text I want to reference"
ActiveSheet.PageSetup.FirstPage.CenterHeader.Text = ""

if I change the RightHeader

ActiveSheet.PageSetup.RightHeader = otherSheet.Range("A2").Value

it returns an error. Run-time error '1004': "Unable to set the RightHeader property of the PageSetup class"

I've been pondering about this problem. To simply put, I want to automate making Executive Summary for our company. I want to add Right Header on pages 2 onwards while leaving the first page with blank header. The problem is, the text I want to use is a combination of text from different references. I did concatenate it into a single cell on another sheet and I want to use that cell as the reference for my header. Can someone help me on this. Thank you so much in advance.

I tried vba using this code

ActiveSheet.PageSetup.DifferentFirstPageHeaderFooter = True
ActiveSheet.PageSetup.RightHeader = "the text I want to reference"
ActiveSheet.PageSetup.FirstPage.CenterHeader.Text = ""

if I change the RightHeader

ActiveSheet.PageSetup.RightHeader = otherSheet.Range("A2").Value

it returns an error. Run-time error '1004': "Unable to set the RightHeader property of the PageSetup class"

Share asked 23 hours ago Light HouseLight House 1 New contributor Light House is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 8
  • 1 Did you check carefully what type of variable otherSheet? or do you set proper sheet to otherSheet? – Harun24hr Commented 23 hours ago
  • @Harun24hr If sheet doesn't exist it is an Object required error for me. – Black cat Commented 23 hours ago
  • @Blackcat Yes. OP's codes seems okay but he is getting error. – Harun24hr Commented 23 hours ago
  • I googled some and maybe printer driver can be the problem. Restart your PC. – Black cat Commented 23 hours ago
  • 1 I encountered problems when the total length of left plus middle plus right header text gets too long. – FunThomas Commented 20 hours ago
 |  Show 3 more comments

1 Answer 1

Reset to default 0

Below codes works to me where Sheet2 C1 cell has context Test Header.

ActiveSheet.PageSetup.DifferentFirstPageHeaderFooter = True
ActiveSheet.PageSetup.RightHeader = Sheets("Sheet2").Range("C1").Text
ActiveSheet.PageSetup.FirstPage.CenterHeader.Text = ""
发布评论

评论列表(0)

  1. 暂无评论