Help me with macros

Joined
Oct 28, 2002
Messages
28
I have made a user form with a text box and a button, i want a macro assigned to the button which takes the text from the text box and puts it in the header and also puts the date in the footer
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
WELCOME TO THE BOARD

This should do the trick:

Private Sub CommandButton1_Click()
With Sheets("Sheet1").PageSetup
.CenterHeader = TextBox1.Value
.CenterFooter = Date
End With
End Sub

Did that do the trick?
 
Upvote 0
Thanks a lot that worked really well.


Private Sub CommandButton1_Click()
With Sheets("Sheet1").PageSetup
.CenterHeader = TextBox1.Value
.CenterFooter = Date
End With
End Sub

But can you make it so the header/footer is applied to all sheets, and also for the form to close after header/footer has been done.
 
Upvote 0
On 2002-10-29 16:44, All the **** names are taken wrote:
Thanks a lot that worked really well.


Private Sub CommandButton1_Click()
With Sheets("Sheet1").PageSetup
.CenterHeader = TextBox1.Value
.CenterFooter = Date
End With
End Sub

But can you make it so the header/footer is applied to all sheets, and also for the form to close after header/footer has been done.

See if this works:

Private Sub CommandButton1_Click()
With ActiveWorkBook.Worksheets.PageSetup
.CenterHeader = TextBox1.Value
.CenterFooter = Date
End With
Unload Me
' Me is just another way of saying UserForm
End Sub
 
Upvote 0
I was taking a guess on that last one. Otherwise, you should be able to copy and paste the code. Instead of Sheets("blahblah") change it to ActiveSheet.
 
Upvote 0
There's no direct way of assigning the same PageSetup to all worksheets in a workbook, in VBA, you have to loop through each of them (Unlike within Excel)
 
Upvote 0
JPG Hi mate

Would
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select

With
.... code

End with not work? Just an idea
 
Upvote 0
No Jack, doesn't work... MS has documented it, there are tricks, like using XLM macros, or copying sheets, but, no, that won't work... sucks, doesn't it ?
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top