Input Box BeforePrint with input in foot

q1911

New Member
Joined
Apr 10, 2013
Messages
10
Hello- I had a VBA code to display an error message to an user based on a cell. I am trying to change it from a MsgBox to an input box and then put that entered input into into the left footer.

so a user gets the message, they input comments, if they hit OK, it prints with the comments in the left.footer, if they hit Cancel it goes back to the sheet.

The two areas to focus on are:
  1. 'this is the dialog box
  2. 'this is the left footer

TIA

VBA Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
'This macro runs when the sheet is printed. It checks to see if wages are being made,
'if wages are not made, a popup will conifrm RVP approval with the user.
'It will print a footer stating it was printed not making wages


'This removes all footers prior
With ActiveSheet.PageSetup
    .LeftHeader = ""
    .CenterHeader = ""
    .RightHeader = ""
    .LeftFooter = ""
    .CenterFooter = ""
    .RightFooter = ""
End With

'This checks if wages are made
If Range("L1") >= 1 Then

'this is the dialog box
Dim i As Variant
With Application
    .EnableEvents = 0
i = InputBox("You are scheduling to miss budgeted wages. RVP approval is needed.", "Missing Wages!", "Enter RVP's approval/comments here")
If Not Confirm = vbOK Then Cancel = True
    .EnableEvents = 1
    
End With
End If

'This adds the version to the footer
With ActiveSheet.PageSetup
    .RightFooter = Worksheets("Change Log").Range("G4")
End With

With ActiveSheet.PageSetup
    .CenterFooter = "&BPrinted: &B&D &I&T"
End With

'this is the left footer
With ActiveSheet.PageSetup
    .LeftFooter = "Printed not making wages with the following comments:" & i
End With


End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I got it all working except, I need to make it so when they hit cancel, it doesn't print:

VBA Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
'This macro runs when the sheet is printed. It checks to see if wages are being made,
'if wages are not made, a popup will conifrm RVP approval with the user.
'It will print a footer stating it was printed not making wages


'This removes all footers prior
With ActiveSheet.PageSetup
    .LeftHeader = ""
    .CenterHeader = ""
    .RightHeader = ""
    .LeftFooter = ""
    .CenterFooter = ""
    .RightFooter = ""
End With

'This checks if wages are made
If Range("L1") >= 1 Then

'this is the dialog box
Dim i As Variant
With Application

i = InputBox("You are scheduling to miss budgeted wages. RVP approval is needed.", "Missing Wages!", "Enter RVP's approval/comments here")
If Not Confirm = ybYes Then Cancel = True
 
      
End With

With ActiveSheet.PageSetup
    .LeftFooter = "Comments:" & i
End With

End If

'This adds the version to the footer
With ActiveSheet.PageSetup
    .RightFooter = Worksheets("Change Log").Range("G4")
End With

With ActiveSheet.PageSetup
    .CenterFooter = "&BPrinted: &B&D &I&T"
End With



End Sub
 
Upvote 0
Hi q1911,

you assign the variable i to the InputBox but you check for confirm.

Try

VBA Code:
'this is the dialog box
    varRet = InputBox("You are scheduling to miss budgeted wages. RVP approval is needed.", "Missing Wages!", "Enter RVP's approval/comments here")
    If Len(varRet) = 0 Then
      Cancel = True
      Exit Sub
    End If
End If

Ciao,
Holger
 
Upvote 0
Solution
Hi q1911,

you assign the variable i to the InputBox but you check for confirm.

Try

VBA Code:
'this is the dialog box
    varRet = InputBox("You are scheduling to miss budgeted wages. RVP approval is needed.", "Missing Wages!", "Enter RVP's approval/comments here")
    If Len(varRet) = 0 Then
      Cancel = True
      Exit Sub
    End If
End If

Thank y



This works, thank you!!!!
 
Upvote 0
like this:

Rich (BB code):
Private Sub Workbook_BeforePrint(Cancel As Boolean)
'This macro runs when the sheet is printed. It checks to see if wages are being made,
'if wages are not made, a popup will conifrm RVP approval with the user.
'It will print a footer stating it was printed not making wages
Dim varRet As Variant

'This removes all footers prior
With ActiveSheet.PageSetup
    .LeftHeader = ""
    .CenterHeader = ""
    .RightHeader = ""
    .LeftFooter = ""
    .CenterFooter = ""
    .RightFooter = ""
End With

'This checks if wages are made
If Range("L1") >= 1 Then

'this is the dialog box
    varRet = InputBox("You are scheduling to miss budgeted wages. RVP approval is needed.", "Missing Wages!", "Enter RVP's approval/comments here")
    If Len(varRet) = 0 Then
      Cancel = True
      Exit Sub
    End If
End If

'This adds the version to the footer
With ActiveSheet.PageSetup
    .RightFooter = Worksheets("Change Log").Range("G4")
End With

With ActiveSheet.PageSetup
    .CenterFooter = "&BPrinted: &B&D &I&T"
End With

'this is the left footer
With ActiveSheet.PageSetup
    .LeftFooter = "Printed not making wages with the following comments:" & varRet
End With

End Sub

Holger
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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