perianors Using VBA to Fermat Lng Documents inthe 2007 Office System ina Fracten ofthe Time
Using VBA to Format Long Documents in the 2007 Office System in
a Fraction of the Time
Summary: nvodices and Gemonstates ont use bes hops, condorlsatarens, and looping statements format lang dace wth ists handle Mires Visual Bsc
Stephan ge souetne Micosl fee MVP
Applies Maro Oe cl 2007, Miran Office PowerPoint 207, Mics Oe Woe 2017, and Vcosf Vins Bae or Appsons
1 Tete Wok You Do. te Rete Your Ress le
1 Using opt Pear pete Tks
1 dang Poneto Your Mt win Contions
1+ rang Less Code by sing roping Statements
*+ wa typ of Document De Younes Format
+ Adana Resouces
1 oi the ator
The Less Work You Do, the Better Your Results Will Be
Wate the vide: Ung WB to Femat Long Docunentsin the 207 Off Sistem na Fraction of the Tine
‘ask tng a por fomateddacumtor changing the formating of along document inte Te Row you have
fr descnes nom at you dont hae the
wondered here aos wy. Well wonder
ted your ecrded Microtat Vil aor Appkton (VB) cosa a fe sl ine fade tat an abe you to
Tiare seames st you a naw hows aes he Wier Vil Bear VK anata you hve soma fatty Wh he Ee
ren t0 VBA Gur out Taking he 2007 ce Ste Further th VBA ara Open XM Feats ora
chon tothe deere beeen cod
Using Loops to Perform Repetitive Tasks
yeu hve rcones macros you new hatyu canard number of stn 3 dg mao Sut thst ecard sets can any con yeu ecto, ihn fomsting ong
vee yu have to mana un the mec a selacng cach idea te pooch ore tbl
cues recoded mocrs Can be very tahoe tse
tena st ens of cose on 5» ap tat enable ou fn he Maco
non you sect without having tcl ha conten fe yuan
or allinsances ofthe tet pe Wat you tees oyna
For cramp nth tek efetencea er sing te 2007 Ofc Sytem ater wth VBA ap Open XL ort yous the flowing recorddans eats vera of he sae
coe ortornating a abe
+ Toe the recorder hon hare you nwt hci eachabh inthe document ana han or.
sb ForacnyTabtes()
Selection Tables(1)-St7e =
Selection Style = ActivebocorentStylest*hesding 2°)
Salecston abler(2) 0 9c€
Selection ables(1) Avtar stathavior (wdhutoF Stix)
SetectfonsTables(1). tows. Al pret oak igeRocorter
hipsimsdn microsch.comfonusfibearylscSS4817 aspx 48perianors Using VBA to Fermat Lng Documents inthe 2007 Office System ina Fracten ofthe Time
‘selection Columns Preferresuldth = InhesToPots(0.6)
na sah
*|
sup Formsenyrables()
Te Rosa) -targe-Style ~Actovedocrent Styes(*eudng 2")
Sstoctitoritanavion (dhuteritrixes)
‘tbccoluns,Preterreiath = LncesToPoint(0.6)
+ sete im satementto cre vale fn VBA vl re ad for many posts nd mary yes fd. ntiscas an objet arable sete to veges ble
beet becuse mre ingen sop hough te clean of alse he caver Ayosgle rom ea aptanumate ens ts eg wey 3 rm
ora underscores but doesnot crt space nd dows ot ole 3 btn VBA erm The espace or slang variable nase pk once nme a fs
‘hepurpose a evar
Dore
Desiring th objec able ants VBA 9 reognze hata eth part ype of eet So or ample when you yp a pao ar Tb intima, 908
‘tthe Aocompltet ako known a eevee of aval propers and methos or tre Wore Table chet
+ TheFor Ech. Next satement sth ap hl wags woud he et factions you wan peo on each bei he document
‘The Fr Each orton ofthe statment testa for ach table nthe clon fal eles nth dora you wan operon he nde st of cons.
1 The Next zatanent mare he and ofthe oop, Hee apes elow the st factions llth ade to moves he mtb th ealecion nd thee of
sions ga The oop atonal nde arth ser rater on he et ajet nt coleton
Dow
Ty the moctsin his ari for yous open th VE sr thon one grt merce Made
cade module nt which you can pat the code rom ths aril
How Many Ways Can You Loop?
Inthe previo exp you so hom jt thes of code ane fr the vate dean and bo forthe op an peel se you hos of werk So, yo re roby
prety Fapey wh the ae fing VBA ort your dosent: Bu how wl ou The to sn ven nore te get ston mre Reky?
‘The For Each-Mext stern hops hough lobes ina colon Felling ae ote oman types loops ha ou can we oun your code stomatal on alipecbjes
+ Foret steed of sng on each ject a allen» For Newt siemens out spel the abject hat you natal on sing 9 cue Fr eae
+ Do. 29p:A De.oop satan seve vrtons tht enable yout ep hough chet alter wile a ate le ue ui sateen! becomes For
ceample yur cocumart nt alles 6 exceod coin page lng you may want runs orating macs nl whle the page count el he masinum pert
west
Forkalp sting thc satan pr otoops, sella the cade rates cute he ae,
Adding Power to Your Macro with Conditions
‘a he cette hive viene his pont can defn save out 3 nce youre fommating rea docantia he eno eance ae hte orang you nee i
rot uke es saghtoread as te noose oth ait For exonpl wha te formating shaw eae ony pesto th ten tables m your deciart ad th ancl bes
reresometing se ental?
‘wo ypes ef conan stern ate salle heb simplify hs ype completion H.Then. he stateens ad Select Case terns
‘Tousesconstionl sateen you us nto enya contin tat te oral Re ht equ he sam oti
+ Poohpe al otyou tn alesse fou columns sane al rani sles ate restr than fe coin Int aston ty an He Than ie ern
ve
sup Formaerabtest¢()
‘oTb.Style = “Light shacing ~ Accent 4”
hipsimsdn microsch.comfon usfibearylocSS4817 aspx 28perianors Using VBA to Fermat Lng Documents inthe 2007 Office System ina Fracten ofthe Time
ove .tous1) tang Styie = actsvesoeanent.Styes(Headieg 2°)
Te.artoritaeavior (aAutoritFixes)
‘sTeccalums.Proferrediath = rachestaPoints(0.6)
oveSeyle = “Rodtur List 2 - sccons
STE Ao tage Stye = Athen Stes hg £)
‘Thebans sch i qute lobe, You a sue fh Elza orion ofthe sttenan tn 2 fang conten ru ans co nating ster You an ao
Wosthenetbe str,
On.
ve
cendetaguents ins Engle exaintion ate sa parenhees to gaupagunens you wuld namaste ems
(what tbh fe are stesy uted an the ls you acuta you nado ape rant omating baad on the eit able se
owl
sub rormarablesselect()
For tach oth Tr Activiocanent Tables
Sslece ave slb.seyle
ase "Ligh Shading = Aecant 4°
oT Autor Haenavion (atutoFitr ie)
Croicatums. referee inebesorotes(.6)
ovbetutorstannavion watutotitngan)
roitorsAbigmert = atlsgtonet=
oTbseyle = “hashun List = accons
‘Ae you set in thi ape, Select ate canbe oe effin than an H-Then Ee sctue whee ether scr ype ork Notice ha the canton dan he
Selc Care nea tn does rated ob repete neach nial au lz nis far shonin he thd cane sine nh rouse that ou can Soup
raph cars en they equre thes actions by emp searing en wth 3 comma
On
‘the Ee stent an Tene ttt, the Case Eton 2 Sbet Cesc the delat acon hat ts edo apy acta tl
ineance ster han hore pees constan ema, thera you do not wat oak eon oh ay blr uns thay wae ane heer pecan Case
Street neh sactre selon the Cae he saree
Writing Less Code by Using Grouping Statements
‘he sample macros ursta donors loops and condions in ie arte notin ts th obec vrei rapate ora I of cots pertain on the ried
sect Bt now tha yuve gro scstomed tthe ena VBA can save you om eels ake, een ht een eto much wor?
Infact file iting VBA cade you rly have type the sae thingie So, ited of ping that arabe on ach neues WHR tater to group aa the acon ht you
(rat tote on tesa ject Take a bok she et arson of Uw ec mace shown evar ater ang a With sateen
sub Formuayrabzes()
bin om a Table
Style = “Lip Shasing = Accent 4°
ows(:).Aange Style ~ Act ivabocanertStyla(“hesding 2°)
‘ator stbchvior (wiAstorsth xed)
“hows. Alsenne~ wai fenocentar
[oluane Srtorvadnsdth = dnchestecints(@.6)
hipsimsdn microsch.comfonuslibrarlocSS4817 aspxperianors Using VBA to Fermat Lng Documents inthe 2007 Office System ina Fracten ofthe Time
hen examining te preceing mac, nce theellowlng:
+ Tew satement i ped wth a equa End With stator at ndeates he ead of he gougng
1+ The Whe fad With cure iene iin he ep, hen ou rat atamentsinyour msc. 2ch a ung s With ftament 3 canon tamer th) wing
bop, iy cvefl tron tote nesting ode for eple you pice nd With te Hex Tb, he mace wouTs ton,
rato growing stern’ can sae franca of ve and yg Using grouping Satemens sao an moran best pace oer Fou ma ve we mote
‘vp code beats con hep you code un uch mare cent Thal when yu reference the cljet jst enc fr wet fection the program cn aces at ebet
What Type of Document Do You Need to Format?
‘oy 2th aes harehoan yu how tors YEA macro for formating late of able in 3 ord docu: ht? Wrong, hia hon you 3 fw cre VBA cong tht
yes con use on hole ype of content you hve in whatever ype of docimenyov nad to oman the 207 Of syste ncn cl, PowerPoint ray ote chet
VB the oes ue 2s bee paragraph) a wat you an do to those objets ate pects the program which You Woking, Bt many fhe cnceptz—suchas the
loops conden atment ane grouping ssterent dese he ae undetlying VBA concep that wok the same srs what pagan you¥eWorng im
Far ensmpesvpote at you ae wating on fg PowerPoint 207 presenttion wth sve ebm members ad ach em merba ha ed shape to dram agra bt thy
och se tet es shes sd alert omatng?
‘Thefllonng sample acto combines eer of the concepts emanated inthe eto change nd forma ose saps fr constancy. Nee how ml ops, cndtona
sllerent and even 9 rousing statement ae neste ints cave Son wth js shane cae, you cn edn ep dees of shes
ve
1
Sub Ftasapee()
Din op shape
or cach ap Th oS Shapes|
ten 959
1 SSp-1ype « easkutesnpe Then
DhtaSnapeype « neashapeouraeakectong
[UL rarecttonOnjectThenecolor = neoThencoDorteeent2
Line ForecoteronjectT¥eneColor = wasTmeneCooraccent]
cise
“run. forecoton OnjectTnenecolor = nsoThenecotortceenth
Line ForecoleronjectTneneColor ~ nastmeneCooraccent2
‘mace mers warendour mun tno yurpeanaton consi ser Sven se te erent shapes Sut what to erin he pratesion nas 38 es?
{aa so of my tavorte ook btn tat ae Pe he Chage shape etre a Shape Quick Ses in PowerPoint to ince ae af teed afew des ht ao show my
teem to ae Smartt gph ioe of shapes for et ne presentation ut that or onthe ice)
Conclusion
Sa a2yeu em mere about hw mu you can with VBA hove fan art sve ire wile yore at t Sut ako remember tht VBA sone f many powell stb fr
formating your doves ad shay seh slo soon oh ate
Additional Resources
1 wate he Ves Using ¥BA to Format Long Documents nthe 207 Ofc Sytem na Faction of the Tine
1 Meas Using VBA Ee On Sse Than You Thin
+ Trealestecting Wierd 2007 Decaments More Easy Usg VBA
1 SON oes Deelner Cone
hipsimsdn microseh.comfonusfibrarylocSS4817 aspx 48perianors Using VBA to Fermat Lng Documents inthe 2007 Office System ina Fracten ofthe Time
+ wicoso offen 2007
About the Author
Stephanie agar Micros ce Sytem MVP andthe attr of wo boots, Aancd Mics fice carn 2007 Eon ase ut anos tie Douek
writes presents ans eestes content for Mico You an tech Stephanie through er lag arate" *
hipsimsdn microsch.comfonuslibearlscSS4817 aspx