using VBA when printing

K

Khalil Handal

Hi,
Is there a way to print a sntence (text) in a workbook whenever a print
command is illustrated?
 
N

Nick Hodge

Khalil

You could use a workbook_beforeprint() event, like so (It puts I was printed
on [Current date/time] in A1 on Sheet1)

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Worksheets("Sheet1").Range("A1").Value = _
"I was printed on " & Now()
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
[email protected]
www.nickhodge.co.uk
 
K

Khalil Handal

Hi Nick,
I put the code in "Module" after changing the name of the sheet and added
the text in cell A1 but it didn't work. Is this the right place?
To make it more clear:
1- Cell A1 is not in the printing range (I have selected print area for
each sheet).
2- I need the sentence for all the sheets in the worbook and not only for
sheet1; in my file the name is "Certificates".
3- This sentence should appear at the bottom of each page on the left side.

In other words:
It might be like having a footer on the left side for anything that is
printed in all the sheets in the workbook.



Nick Hodge said:
Khalil

You could use a workbook_beforeprint() event, like so (It puts I was
printed on [Current date/time] in A1 on Sheet1)

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Worksheets("Sheet1").Range("A1").Value = _
"I was printed on " & Now()
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
[email protected]
www.nickhodge.co.uk


Khalil Handal said:
Hi,
Is there a way to print a sntence (text) in a workbook whenever a print
command is illustrated?
 
B

Bill Kuunders

Khalil,
Have you tried.....
file
page setup
header/ footer
custom footer
add the sentence in the left part of the footer.


It can be done with vba as Nick Hodge has done
You would need to enter that macro into the "this workbook code" "before
print ".
But you can do that manually for each sheet / book as well.

regards
Bill



Khalil Handal said:
Hi Nick,
I put the code in "Module" after changing the name of the sheet and added
the text in cell A1 but it didn't work. Is this the right place?
To make it more clear:
1- Cell A1 is not in the printing range (I have selected print area for
each sheet).
2- I need the sentence for all the sheets in the worbook and not only for
sheet1; in my file the name is "Certificates".
3- This sentence should appear at the bottom of each page on the left
side.

In other words:
It might be like having a footer on the left side for anything that is
printed in all the sheets in the workbook.



Nick Hodge said:
Khalil

You could use a workbook_beforeprint() event, like so (It puts I was
printed on [Current date/time] in A1 on Sheet1)

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Worksheets("Sheet1").Range("A1").Value = _
"I was printed on " & Now()
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
[email protected]
www.nickhodge.co.uk


Khalil Handal said:
Hi,
Is there a way to print a sntence (text) in a workbook whenever a print
command is illustrated?
 
K

Khalil Handal

Hi Bill,
You had an idea about the file I am working with. I will try your
suggestion! the idea was not very clear to me about how to do it (for all
the sheets or even a range).
Khalil

Bill Kuunders said:
Khalil,
Have you tried.....
file
page setup
header/ footer
custom footer
add the sentence in the left part of the footer.


It can be done with vba as Nick Hodge has done
You would need to enter that macro into the "this workbook code" "before
print ".
But you can do that manually for each sheet / book as well.

regards
Bill



Khalil Handal said:
Hi Nick,
I put the code in "Module" after changing the name of the sheet and added
the text in cell A1 but it didn't work. Is this the right place?
To make it more clear:
1- Cell A1 is not in the printing range (I have selected print area for
each sheet).
2- I need the sentence for all the sheets in the worbook and not only
for sheet1; in my file the name is "Certificates".
3- This sentence should appear at the bottom of each page on the left
side.

In other words:
It might be like having a footer on the left side for anything that is
printed in all the sheets in the workbook.



Nick Hodge said:
Khalil

You could use a workbook_beforeprint() event, like so (It puts I was
printed on [Current date/time] in A1 on Sheet1)

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Worksheets("Sheet1").Range("A1").Value = _
"I was printed on " & Now()
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
[email protected]
www.nickhodge.co.uk


Hi,
Is there a way to print a sntence (text) in a workbook whenever a print
command is illustrated?
 
N

Nick Hodge

Khalil

This code should go in the ThisWorkbook module not a standard one. To access
it you can right click the small Excel Icon at the upper left of the Excel
window (Not the top one, but the one for the workbook) and select view code.
Paste it in the resulting window. This should fire just before any print
operation for the whole workbook.

This may be better as you add worksheets which will otherwise need to have
the footer added

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
[email protected]
www.nickhodge.co.uk


Khalil Handal said:
Hi Nick,
I put the code in "Module" after changing the name of the sheet and added
the text in cell A1 but it didn't work. Is this the right place?
To make it more clear:
1- Cell A1 is not in the printing range (I have selected print area for
each sheet).
2- I need the sentence for all the sheets in the worbook and not only for
sheet1; in my file the name is "Certificates".
3- This sentence should appear at the bottom of each page on the left
side.

In other words:
It might be like having a footer on the left side for anything that is
printed in all the sheets in the workbook.



Nick Hodge said:
Khalil

You could use a workbook_beforeprint() event, like so (It puts I was
printed on [Current date/time] in A1 on Sheet1)

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Worksheets("Sheet1").Range("A1").Value = _
"I was printed on " & Now()
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
[email protected]
www.nickhodge.co.uk


Khalil Handal said:
Hi,
Is there a way to print a sntence (text) in a workbook whenever a print
command is illustrated?
 
K

Khalil Handal

Thanks.

Khalil


Nick Hodge said:
Khalil

This code should go in the ThisWorkbook module not a standard one. To
access it you can right click the small Excel Icon at the upper left of
the Excel window (Not the top one, but the one for the workbook) and
select view code. Paste it in the resulting window. This should fire just
before any print operation for the whole workbook.

This may be better as you add worksheets which will otherwise need to have
the footer added

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
[email protected]
www.nickhodge.co.uk


Khalil Handal said:
Hi Nick,
I put the code in "Module" after changing the name of the sheet and added
the text in cell A1 but it didn't work. Is this the right place?
To make it more clear:
1- Cell A1 is not in the printing range (I have selected print area for
each sheet).
2- I need the sentence for all the sheets in the worbook and not only
for sheet1; in my file the name is "Certificates".
3- This sentence should appear at the bottom of each page on the left
side.

In other words:
It might be like having a footer on the left side for anything that is
printed in all the sheets in the workbook.



Nick Hodge said:
Khalil

You could use a workbook_beforeprint() event, like so (It puts I was
printed on [Current date/time] in A1 on Sheet1)

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Worksheets("Sheet1").Range("A1").Value = _
"I was printed on " & Now()
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
[email protected]
www.nickhodge.co.uk


Hi,
Is there a way to print a sntence (text) in a workbook whenever a print
command is illustrated?
 
Top