ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   InputBox / VBA question ok = print, cancel = exit (https://www.excelbanter.com/excel-worksheet-functions/153629-inputbox-vba-question-ok-%3D-print-cancel-%3D-exit.html)

todd78

InputBox / VBA question ok = print, cancel = exit
 
Here is my code. Keep in mind I am by no means an experienced Visual Basic or
VBA programmer:

Dim Response As String
Sub printinvoice()
'
' printinvoice Macro
' Macro recorded 8/7/2007 by tcobane
'
' Keyboard Shortcut: Ctrl+Shift+V
'
Sheets("C").Select
Response = Application.InputBox(prompt:="Enter Invoice Number", Type:=2,
Default:="", Title:="Print Invoice")
If Trim(Response) = "" Or Empty Then
Range("H14") = " "
Exit Sub
Else
Range("H14") = Response
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("A").Select
End If
End Sub
--------------------------------------------------------------------------------

What I'm trying to do is make it so the user inputs a number into the input
box, the number is transferred to Cell H14 on sheet C and then sheet C is
printed. If the user hits "cancel" then nothing is printed and the user is
returned to sheet A.

As it sits now, hitting cancel will still print sheet C with a "0" in cell
H14.

Any tips are appreciated. Someone borrowed my VB textbook from college so I
have no other resources at the moment.



Bob Phillips

InputBox / VBA question ok = print, cancel = exit
 
Dim Response As String
Sub printinvoice()
Sheets("C").Select
Response = Application.InputBox( _
prompt:="Enter Invoice Number", _
Type:=2, Default:="", _
Title:="Print Invoice")
If Trim(Response) = "False" Or Empty Then
Range("H14").Value = " "
Exit Sub
Else
Range("H14").Value = Response
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("A").Select
End If
End Sub




--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"todd78" wrote in message
...
Here is my code. Keep in mind I am by no means an experienced Visual Basic
or
VBA programmer:

Dim Response As String
Sub printinvoice()
'
' printinvoice Macro
' Macro recorded 8/7/2007 by tcobane
'
' Keyboard Shortcut: Ctrl+Shift+V
'
Sheets("C").Select
Response = Application.InputBox(prompt:="Enter Invoice Number",
Type:=2,
Default:="", Title:="Print Invoice")
If Trim(Response) = "" Or Empty Then
Range("H14") = " "
Exit Sub
Else
Range("H14") = Response
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("A").Select
End If
End Sub
--------------------------------------------------------------------------------

What I'm trying to do is make it so the user inputs a number into the
input
box, the number is transferred to Cell H14 on sheet C and then sheet C is
printed. If the user hits "cancel" then nothing is printed and the user is
returned to sheet A.

As it sits now, hitting cancel will still print sheet C with a "0" in cell
H14.

Any tips are appreciated. Someone borrowed my VB textbook from college so
I
have no other resources at the moment.





Bernard Liengme

InputBox / VBA question ok = print, cancel = exit
 
This worked for me
Sub printinvoice()
'
' printinvoice Macro
' Macro recorded 8/7/2007 by tcobane
' Revised by B Liengme
'
' Keyboard Shortcut: Ctrl+Shift+V
'
Dim Response As String
Sheets("C").Select
Response = InputBox("Enter Invoice Number", "Print Invoice")
Debug.Print "*" & Response & "*"
If Response = "" Then
Range("H14") = " "
Exit Sub
Else
Range("H14") = Response
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("A").Select
End If
End Sub


best wishes
--
Bernard V Liengme
Microsoft Excel MVP
www.stfx.ca/people/bliengme
remove caps from email

"todd78" wrote in message
...
Here is my code. Keep in mind I am by no means an experienced Visual Basic
or
VBA programmer:

Dim Response As String
Sub printinvoice()
'
' printinvoice Macro
' Macro recorded 8/7/2007 by tcobane
'
' Keyboard Shortcut: Ctrl+Shift+V
'
Sheets("C").Select
Response = Application.InputBox(prompt:="Enter Invoice Number",
Type:=2,
Default:="", Title:="Print Invoice")
If Trim(Response) = "" Or Empty Then
Range("H14") = " "
Exit Sub
Else
Range("H14") = Response
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("A").Select
End If
End Sub
--------------------------------------------------------------------------------

What I'm trying to do is make it so the user inputs a number into the
input
box, the number is transferred to Cell H14 on sheet C and then sheet C is
printed. If the user hits "cancel" then nothing is printed and the user is
returned to sheet A.

As it sits now, hitting cancel will still print sheet C with a "0" in cell
H14.

Any tips are appreciated. Someone borrowed my VB textbook from college so
I
have no other resources at the moment.





todd78

InputBox / VBA question ok = print, cancel = exit
 
If HTH = happy to help then thank you very much, Bob! It appears to work as
desired now. Not sure what's up with my e-mail address. I registered with my
gmail account.

"Bob Phillips" wrote:

Dim Response As String
Sub printinvoice()
Sheets("C").Select
Response = Application.InputBox( _
prompt:="Enter Invoice Number", _
Type:=2, Default:="", _
Title:="Print Invoice")
If Trim(Response) = "False" Or Empty Then
Range("H14").Value = " "
Exit Sub
Else
Range("H14").Value = Response
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("A").Select
End If
End Sub




--
HTH
Bob
(there's no email, no snail mail, but somewhere should be gmail in my addy)



Bob Phillips

InputBox / VBA question ok = print, cancel = exit
 
It means 'Hope That Helps, although I am happy if it does <bg

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"todd78" wrote in message
...
If HTH = happy to help then thank you very much, Bob! It appears to work
as
desired now. Not sure what's up with my e-mail address. I registered with
my
gmail account.

"Bob Phillips" wrote:

Dim Response As String
Sub printinvoice()
Sheets("C").Select
Response = Application.InputBox( _
prompt:="Enter Invoice Number", _
Type:=2, Default:="", _
Title:="Print Invoice")
If Trim(Response) = "False" Or Empty Then
Range("H14").Value = " "
Exit Sub
Else
Range("H14").Value = Response
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("A").Select
End If
End Sub




--
HTH
Bob
(there's no email, no snail mail, but somewhere should be gmail in my
addy)






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

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