iTechtalk

Quick Search

Go Advanced

Member Login

Not registered? | Forgot Password
 
Register
Welcome
 
iTechtalk > Tutorials > Applications » Visual Basic For Applications In Microsoft Office 2007
Reply
Old 11-15-2008, 06:09 AM   #1 (permalink)
 
Shuella's Avatar
 
Junior Member
Join Date: Nov 2008
Posts: 2
Smile Visual Basic For Applications In Microsoft Office 2007

Visual Basic For Applications In Microsoft Office 2007


Not all macros are keyboard based. In addition to the keyboard-recorded macros, lots of macros provide additional commands that go further than the simple selection of menu options. Microsoft standardized the Visual Basic for Application (VBA) programming language several years ago to form the foundation behind macros.

When you record a macro, your Office application isn’t in fact recording your keystrokes and mouse clicks, even though that is the practical upshot of what it’s doing. In reality, every time you press a key, select from a menu, type text, or click a button, the application adds a new VBA command to that macro’s program. Until you learn a programming language, its programs can be cryptic in reality. For example, a macro you record that colors a selected paragraph’s background yellow and converts the paragraph’s first letter to a drop cap letter is actually a VBA program that looks like this:

Sub DropCap_YellowBN()



‘ DropCap_YellowBG Macro

‘ Follows company standards for lead-in paragraphs so the initial letter


‘ has a drop cap and the paragraph is colored with a yellow background.


Selection.Shading.Texture = wdTextureNone

Selection.Shading.ForegroundPatternColor = wdColorAutomatic

Selection.Shading.BackgroundPatternColor = wdColorYellow

Selection.MoveLeft Unit:=wdCharacter, Count:=1

Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend

With Selection.Paragraphs(1).DropCap

.Position = wdDropNormal

.FontName = “+Body”

.LinesToDrop = 3

.DistanceFromtext = InchesToPointsi(0)

End With

Windows(“Computers and You”).Activate

End Sub


Recording your keystrokes and mouse clicks is a lot easier than writing all those VBA programming language statements! However, if you knew VBA, you could have written this code in its place of recording the macro and get the same results. In Office 2007, you get a complete Visual Basic environment from which you can write VBA programs that control almost every feature of your document work. From the Developer ribbon, you can click the Visual Basic button to see a programming environment open on your screen.




When you write a Visual Basic program to control an Office application, you’ll use Visual Basic’s own environment.


You might wonder how Visual Basic can supplement and add functionality to an Office application other than automating simple, regular tasks. After all, Excel supports VBA, but with all the worksheet power and commands that Excel already provides, how can a VBA program controlling Excel’s environment and worksheet add any advantage to the Excel user?

If all VBA did was automate simple, regular tasks in recorded macros, VBA would be a welcome addition to Office. Simple recorded macros, although, must run in the same environment and with the same set of worksheets and columns each time. The keyboard macro has no room for uncertainty. For example, what if one of your company divisions was to shut down for remodeling one month? The keyboard macro that you may have recorded to consolidate all your company’s four divisions would consolidate either a blank worksheet or an old one for the missing division’s new data, producing an error.

Because Visual Basic is a complete programming language, the employee who needs such a consolidated report, for example, can write a series of commands that handle unexpected conditions more elegantly than keyboard-recorded macros can. Perhaps the VBA program could read each worksheet and, if data other than zeros shows for the month totals, add that worksheet to the summary but ignore any other worksheet in which the division had no activity for the period. Such a macro—a Visual Basic program written in the VBA language—would work when a recorded macro would not.
Shuella is offline   Reply With Quote
 
Reply

Bookmarks

Tags
applications, microsoft, office 2007, visual basic

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SP2 for Microsoft Office 2007 rajarshidutta007 Technology news 0 04-11-2009 04:21 AM
Visual Basic Tools in Excel 2007 cathode Applications 0 11-22-2008 03:56 AM
The Visual Basic Editor in Excel 2007 evaporation Applications 0 11-21-2008 09:51 AM
Share Office Files With Other Applications In Office 2007 Primospire Applications 0 11-17-2008 11:30 AM
What Else Is New In Microsoft Office 2007? Glenda Applications 0 11-07-2008 10:17 AM


 

Content Relevant URLs by vBSEO 3.3.0