Inputbox for header beforeprint

mfd2112

Board Regular
Joined
Jan 2, 2010
Messages
86
I have some code that will prompt a user to insert their name and the date with an inputbox.
The inputbox will insert the data into the header.
I would like the input box to ask the user to supply info for two places in the left header, one upper most and one lower most, and one place in the right upper. Currently the left lower and right upper is hard coded.
Also the cancel button is not working right.
I looked around and recorded some macros to get to this point but now I’m stuck, any help please is appreciated.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Code:
[COLOR=black][FONT=Courier New]<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]<o:p>Private Sub Workbook_BeforePrint(Cancel As Boolean)[/FONT][/COLOR]
[FONT=Courier New][COLOR=black]'Cancel = True</o:p>[/COLOR][/FONT]
[COLOR=black][FONT=Courier New]<o:p>Dim strMiddle As String[/FONT][/COLOR]
[FONT=Courier New][COLOR=black]Dim strLeft As String[/COLOR][/FONT]
[FONT=Courier New][COLOR=black]'Dim strRight As String[/COLOR][/FONT]
[FONT=Courier New][COLOR=black]Dim i As Integer</o:p>[/COLOR][/FONT]
[COLOR=black][FONT=Courier New]<o:p>strMiddle = GetInput("your name", "Enter Your Name", Application.UserName)[/FONT][/COLOR]
[FONT=Courier New][COLOR=black]strLeft = GetInput("a date", "The Date", Date)[/COLOR][/FONT]
[FONT=Courier New][COLOR=black]'strRight = GetInput("Weather", "The Weather", Weather)</o:p>[/COLOR][/FONT]
[COLOR=black][FONT=Courier New]<o:p>   With ActiveSheet.PageSetup[/FONT][/COLOR]
[FONT=Courier New][COLOR=black]   .LeftHeader = strLeft & Chr(10) & "" & Chr(10) & "Day:_________________"[/COLOR][/FONT]
[FONT=Courier New][COLOR=black]   .CenterHeader = "&20" + strMiddle[/COLOR][/FONT]
[FONT=Courier New][COLOR=black]   .RightHeader = "Weather:_________________"[/COLOR][/FONT]
[FONT=Courier New][COLOR=black]   </o:p>[/COLOR][/FONT]
[COLOR=black][FONT=Courier New]<o:p>   End With[/FONT][/COLOR]
[FONT=Courier New][COLOR=black]End Sub</o:p>[/COLOR][/FONT]
[COLOR=black][FONT=Courier New]<o:p>[/FONT][/COLOR]
[FONT=Courier New][COLOR=black]Function GetInput(ByVal strPrompt As String, strTitle As String, strDefault As String) As String</o:p>[/COLOR][/FONT]
[COLOR=black][FONT=Courier New]<o:p>Dim strInput As Variant</o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]<o:p>   Do[/FONT][/COLOR]
[FONT=Courier New][COLOR=black]   strInput = ""[/COLOR][/FONT]
[FONT=Courier New][COLOR=black]   strInput = Application.InputBox("Please enter " & strPrompt, strTitle, strDefault)[/COLOR][/FONT]
[FONT=Courier New][COLOR=black]   Loop While strInput = "" Or strInput = False</o:p>[/COLOR][/FONT]
[COLOR=black][FONT=Courier New]<o:p>   GetInput = strInput</o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]<o:p>End Function[/FONT][/COLOR]
[FONT=Courier New][COLOR=black]</o:p>[/COLOR][/FONT]
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,224,574
Messages
6,179,626
Members
452,933
Latest member
patv

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