using a input box

  • Thread starter Thread starter ned
  • Start date Start date
N

ned

I have a simple macro for users to click on a command button that prints out
2 sheets. I want to add code when the button is click, a box pops up to
have them type their name. Their name is in the footer along with today's
date. The macro then will continue on with printing the sheets. Thanks
 
Add this to your code:

Dim strName As String
strName = InputBox("Please enter your name.", "Name")

'
' -- Uncomment and use whichever footers you wish
'
'ActiveSheet.PageSetup.LeftFooter = ""
ActiveSheet.PageSetup.CenterFooter = strName & " " & Now
'ActiveSheet.PageSetup.RightFooter = ""

'Add your code to print here
 
what if I want a input box to pop up when I open up a certain workbook.
Here's the code I have so far, but it's not working. I can get it to work
if I run it manually within excel.

Private Sub WorkbookOpen()
Dim strname As String
strname = InputBox("Please type in your name.", "Name")
MsgBox ("Hey " & strname & "! " & "Fill in the yellow cells only")
End Sub
 
Hi Ned,
Here's the code I have so far, but it's not working. I can get it to work
if I run it manually within excel.

Where did you put the code?

It should be in the workbook's ThisWorbook module. You can access this
module by right-clicking the Excel icon at the extreme left of the Menu
toolbar and selecting View Code.

Your code worked for me, providing that it was housed in the correct module.
 
Norman is absolutely correct. What you are doing is running an even
procedure, which is a bit complicated to explain. An event procedur
runs when something happens (in your case, the workbook being opened)
It must be put in the correct place (i.e. the workbook section o
code).

I did notice that your post had WorkbookOpen as the name of th
routine. An event procedure for opening the workbook would be calle
Workbook_Open (notice the underscore). The easiest way to check fo
what event procedures are available is to go to the specific code are
(either a worksheet or the workbook) and click on the left-most dro
down at the top of the screen. In the ThisWorkbook module, if yo
select Workbook from the left drop down, it will give you all of th
events that are associated with the workbook.

Post back with more questions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top