ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB. NET Code to Change Excel Worksheet Header/Footer. (https://www.excelbanter.com/excel-programming/355874-vbulletin-net-code-change-excel-worksheet-header-footer.html)

Elena

VB. NET Code to Change Excel Worksheet Header/Footer.
 
I need the VB.NET code to change the header/footer of an Excel spread sheet,
ASAP.
I am doing it through a VB application. I can change the ranges/cell values
using code, but I do not know how to change things outside of the cell
ranges. I will try and post in an Excel group, but i do not need to change
it in a worksheet, I need to change it through a VB application. For
example, I am using this code to change values in certain cells:

'open excel document
Dim ThisApplication As Excel.Application
ThisApplication = New Excel.Application
' Start Excel and get Application object.
ThisApplication = CreateObject("Excel.Application")
ThisApplication.Visible = True
'connection for package
Dim Wb As Excel.Workbook =
ThisApplication.Workbooks.Open("C:\CDRLReview.xls" )
Dim CDRLWs As Excel.Worksheet = Wb.Worksheets(1)
Dim DIDWs As Excel.Worksheet = Wb.Worksheets(2)

DIDWs.Range("a2").Value = "There is no DID associated with this
CDRL."
DIDWs.Range("a2").Font.ColorIndex = 3
DIDWs.Range("a2").Font.Bold = True

This code works! Yet, I need to change the Worksheet's header in the same
fashion.

I need to know if i can do something like:

DIDWs.Header.Value = <~~ I don' t know what the correct code is, it's just
an example.

Thanks in Advance.
~Elena



Chip Pearson

VB. NET Code to Change Excel Worksheet Header/Footer.
 
Elena,

Try

DIDws.PageSetup.CenterHeader = "Your text"

You can use Left/Center/Right Header/Footer.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Elena" wrote in message
...
I need the VB.NET code to change the header/footer of an Excel
spread sheet,
ASAP.
I am doing it through a VB application. I can change the
ranges/cell values
using code, but I do not know how to change things outside of
the cell
ranges. I will try and post in an Excel group, but i do not
need to change
it in a worksheet, I need to change it through a VB
application. For
example, I am using this code to change values in certain
cells:

'open excel document
Dim ThisApplication As Excel.Application
ThisApplication = New Excel.Application
' Start Excel and get Application object.
ThisApplication = CreateObject("Excel.Application")
ThisApplication.Visible = True
'connection for package
Dim Wb As Excel.Workbook =
ThisApplication.Workbooks.Open("C:\CDRLReview.xls" )
Dim CDRLWs As Excel.Worksheet = Wb.Worksheets(1)
Dim DIDWs As Excel.Worksheet = Wb.Worksheets(2)

DIDWs.Range("a2").Value = "There is no DID
associated with this
CDRL."
DIDWs.Range("a2").Font.ColorIndex = 3
DIDWs.Range("a2").Font.Bold = True

This code works! Yet, I need to change the Worksheet's header
in the same
fashion.

I need to know if i can do something like:

DIDWs.Header.Value = <~~ I don' t know what the correct code
is, it's just
an example.

Thanks in Advance.
~Elena





Elena

VB. NET Code to Change Excel Worksheet Header/Footer.
 
Thank you!


"Chip Pearson" wrote:

Elena,

Try

DIDws.PageSetup.CenterHeader = "Your text"

You can use Left/Center/Right Header/Footer.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Elena" wrote in message
...
I need the VB.NET code to change the header/footer of an Excel
spread sheet,
ASAP.
I am doing it through a VB application. I can change the
ranges/cell values
using code, but I do not know how to change things outside of
the cell
ranges. I will try and post in an Excel group, but i do not
need to change
it in a worksheet, I need to change it through a VB
application. For
example, I am using this code to change values in certain
cells:

'open excel document
Dim ThisApplication As Excel.Application
ThisApplication = New Excel.Application
' Start Excel and get Application object.
ThisApplication = CreateObject("Excel.Application")
ThisApplication.Visible = True
'connection for package
Dim Wb As Excel.Workbook =
ThisApplication.Workbooks.Open("C:\CDRLReview.xls" )
Dim CDRLWs As Excel.Worksheet = Wb.Worksheets(1)
Dim DIDWs As Excel.Worksheet = Wb.Worksheets(2)

DIDWs.Range("a2").Value = "There is no DID
associated with this
CDRL."
DIDWs.Range("a2").Font.ColorIndex = 3
DIDWs.Range("a2").Font.Bold = True

This code works! Yet, I need to change the Worksheet's header
in the same
fashion.

I need to know if i can do something like:

DIDWs.Header.Value = <~~ I don' t know what the correct code
is, it's just
an example.

Thanks in Advance.
~Elena







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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com