Workbook Events - Workbook Before Print event

Excel VBA for Beginners Events in Excel VBA
2 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€85.78
List Price:  €120.09
You save:  €34.31
£74.57
List Price:  £104.41
You save:  £29.83
CA$137.96
List Price:  CA$193.15
You save:  CA$55.19
A$153.09
List Price:  A$214.33
You save:  A$61.24
S$128.82
List Price:  S$180.35
You save:  S$51.53
HK$780.13
List Price:  HK$1,092.22
You save:  HK$312.08
CHF 80.34
List Price:  CHF 112.49
You save:  CHF 32.14
NOK kr1,002.34
List Price:  NOK kr1,403.32
You save:  NOK kr400.97
DKK kr640.19
List Price:  DKK kr896.29
You save:  DKK kr256.10
NZ$170.50
List Price:  NZ$238.70
You save:  NZ$68.20
د.إ367.21
List Price:  د.إ514.11
You save:  د.إ146.90
৳12,161.77
List Price:  ৳17,026.97
You save:  ৳4,865.19
₹8,804.49
List Price:  ₹12,326.64
You save:  ₹3,522.15
RM422.70
List Price:  RM591.80
You save:  RM169.10
₦153,629.63
List Price:  ₦215,087.63
You save:  ₦61,458
₨28,293.93
List Price:  ₨39,612.64
You save:  ₨11,318.70
฿3,234.32
List Price:  ฿4,528.18
You save:  ฿1,293.86
₺4,114.84
List Price:  ₺5,760.95
You save:  ₺1,646.10
B$547.02
List Price:  B$765.85
You save:  B$218.83
R1,762.70
List Price:  R2,467.86
You save:  R705.15
Лв167.91
List Price:  Лв235.08
You save:  Лв67.17
₩138,945.27
List Price:  ₩194,528.94
You save:  ₩55,583.66
₪336.77
List Price:  ₪471.49
You save:  ₪134.72
₱5,729.37
List Price:  ₱8,021.35
You save:  ₱2,291.98
¥14,854.21
List Price:  ¥20,796.49
You save:  ¥5,942.28
MX$1,870.35
List Price:  MX$2,618.57
You save:  MX$748.21
QR364.32
List Price:  QR510.06
You save:  QR145.74
P1,347.77
List Price:  P1,886.93
You save:  P539.16
KSh12,913.70
List Price:  KSh18,079.70
You save:  KSh5,166
E£4,858.94
List Price:  E£6,802.71
You save:  E£1,943.77
ብር14,285.86
List Price:  ብር20,000.78
You save:  ብር5,714.91
Kz91,186.39
List Price:  Kz127,664.59
You save:  Kz36,478.20
CLP$97,354.26
List Price:  CLP$136,299.86
You save:  CLP$38,945.60
CN¥713
List Price:  CN¥998.24
You save:  CN¥285.23
RD$6,298.47
List Price:  RD$8,818.11
You save:  RD$2,519.64
DA12,991.06
List Price:  DA18,188
You save:  DA5,196.94
FJ$226.12
List Price:  FJ$316.58
You save:  FJ$90.46
Q766.32
List Price:  Q1,072.87
You save:  Q306.55
GY$20,908.02
List Price:  GY$29,272.07
You save:  GY$8,364.04
ISK kr12,319.76
List Price:  ISK kr17,248.16
You save:  ISK kr4,928.40
DH904.41
List Price:  DH1,266.21
You save:  DH361.80
L1,648.78
List Price:  L2,308.36
You save:  L659.58
ден5,288.25
List Price:  ден7,403.76
You save:  ден2,115.51
MOP$803.86
List Price:  MOP$1,125.44
You save:  MOP$321.57
N$1,771.48
List Price:  N$2,480.14
You save:  N$708.66
C$3,679.53
List Price:  C$5,151.49
You save:  C$1,471.96
रु14,112.30
List Price:  रु19,757.79
You save:  रु5,645.48
S/353.41
List Price:  S/494.79
You save:  S/141.37
K419.26
List Price:  K586.98
You save:  K167.72
SAR375.19
List Price:  SAR525.29
You save:  SAR150.09
ZK2,368.97
List Price:  ZK3,316.66
You save:  ZK947.68
L435.57
List Price:  L609.82
You save:  L174.24
Kč2,097.30
List Price:  Kč2,936.30
You save:  Kč839
Ft33,774.46
List Price:  Ft47,285.59
You save:  Ft13,511.13
SEK kr943.78
List Price:  SEK kr1,321.33
You save:  SEK kr377.55
ARS$135,932.91
List Price:  ARS$190,311.51
You save:  ARS$54,378.60
Bs690.86
List Price:  Bs967.24
You save:  Bs276.37
COP$400,952.08
List Price:  COP$561,348.96
You save:  COP$160,396.87
₡50,547.65
List Price:  ₡70,768.74
You save:  ₡20,221.08
L2,635.35
List Price:  L3,689.60
You save:  L1,054.24
₲722,145.91
List Price:  ₲1,011,033.16
You save:  ₲288,887.25
$U4,001.81
List Price:  $U5,602.70
You save:  $U1,600.88
zł364.73
List Price:  zł510.64
You save:  zł145.90
Already have an account? Log In

Transcript

Hey guys welcome back. So in this video we're going to discuss the workbook before print event and the workbook before print event. As the name suggests, it runs any code written in that event before printing happens. So to get to that event, you need to open your VBA editor and then you're going to double click on this workbook here and then you're going to click on workbook from this menu and you're going to select before print here from this menu, I'm just going to delete the workbook open event because we don't need it. So it actually works similarly to the workbook before close event and you can see here there is a parameter called cancel and this cancel parameter is Boolean so it takes values of true or false is by default false. However, if you put it equal to true then printing will not be allowed.

If someone tries to print your Excel workbook they are not going to be allowed to print it. So I'm going to put cancel equals true then maybe a message box printing is not allowed. So now I'm going to try to print. So I'm going to go to File, and then print. And then I'm going to click here on the Print button here and it says printing is not allowed. And it's not allowed me to print, you can also do something cool with that, which is that you can be selective of who can print your workbook.

So there is actually a function in Excel VBA that is called environment that can determine what the username of the person who's using the computer is. And you can know what the username of yourself is if you're logged on windows with your user. So you can right here in the immediate window, for example environ after the question mark, okay, so you're asking for a certain value and then inside that inside the environment, you're gonna write username share now asking about the current user name that is using the computer Okay, so I got the username, which is myself, you got actually right here. If When user name is not equal to yours, then cancel equals true, else cancel equals false. Okay, and if so now is somebody else other than myself tries to print the workbook is not going to enable him or her to print, but if it is myself and I'm going to be able to print the workbook so that's a bit of security if you want to.

Okay, so that's it for the workbook before print event. Thank you very much guys for watching this video, and I'll see you on the next one.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.