Programming excel with vba a practical real world guide flavio morgado - The ebook in PDF format wit

Page 1


Visit to download the full and correct content document: https://textbookfull.com/product/programming-excel-with-vba-a-practical-real-world-gu ide-flavio-morgado/

More products digital (pdf, epub, mobi) instant download maybe you interests ...

EXCEL VBA Programming By Examples Programming For Complete Beginners Step By Step Illustrated Guide to Mastering Excel VBA Thanh Tran

https://textbookfull.com/product/excel-vba-programming-byexamples-programming-for-complete-beginners-step-by-stepillustrated-guide-to-mastering-excel-vba-thanh-tran/

Excel VBA Programming For Dummies 5th Edition Michael Alexander

https://textbookfull.com/product/excel-vba-programming-fordummies-5th-edition-michael-alexander/

Introducing Microsoft Access Using Macro Programming Techniques An Introduction to Desktop Database Development by Example 1st Edition Flavio Morgado

https://textbookfull.com/product/introducing-microsoft-accessusing-macro-programming-techniques-an-introduction-to-desktopdatabase-development-by-example-1st-edition-flavio-morgado/

Engineering Analysis Modeling With Excel VBA Version 9 0 9th Edition Matthew E. Moran

https://textbookfull.com/product/engineering-analysis-modelingwith-excel-vba-version-9-0-9th-edition-matthew-e-moran/

Learning Java An Introduction to Real World Programming with Java Marc Loy

https://textbookfull.com/product/learning-java-an-introductionto-real-world-programming-with-java-marc-loy/

VBA for Modelers Developing Decision Support Systems with Microsoft Office Excel 5th Edition S. Christian Albright

https://textbookfull.com/product/vba-for-modelers-developingdecision-support-systems-with-microsoft-office-excel-5th-editions-christian-albright/

Learning Java An Introduction to Real World Programming with Java 5th Edition Marc Loy

https://textbookfull.com/product/learning-java-an-introductionto-real-world-programming-with-java-5th-edition-marc-loy/

Python Network Programming Cookbook Practical solutions to overcome real world networking challenges 2nd Edition Pradeeban Kathiravelu

https://textbookfull.com/product/python-network-programmingcookbook-practical-solutions-to-overcome-real-world-networkingchallenges-2nd-edition-pradeeban-kathiravelu/

Practical Natural Language Processing A Comprehensive Guide to Building Real world Nlp Systems 1st Edition Sowmya Vajjala

https://textbookfull.com/product/practical-natural-languageprocessing-a-comprehensive-guide-to-building-real-world-nlpsystems-1st-edition-sowmya-vajjala/

Programming Excel with VBA

Programming Excel with VBA

A Practical Real-World Guide

Flavio Morgado

Programming Excel with VBA: A Practical Real-World Guide

Flavio Morgado

Rio de Janeiro, Brazil

ISBN-13 (pbk): 978-1-4842-2204-1

DOI 10.1007/978-1-4842-2205-8

Library of Congress Control Number: 2016957877

Copyright © 2016 by Flavio Morgado

ISBN-13 (electronic): 978-1-4842-2205-8

This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.

Cover image designed by FreePik

Managing Director: Welmoed Spahr

Lead Editor: Gwenan Spearing

Technical Reviewer: Fabio Claudio Ferracchiati

Editorial Board: Steve Anglin, Pramila Balan, Laura Berendson, Aaron Black, Louise Corrigan, Jonathan Gennick, Robert Hutchinson, Celestin Suresh John, Nikhil Karkal, James Markham, Susan McDermott, Matthew Moodie, Natalie Pao, Gwenan Spearing

Coordinating Editor: Mark Powers

Copy Editor: Kim Wimpsett

Compositor: SPi Global Indexer: SPi Global Artist: SPi Global

Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer -sbm.com, or visit www.springer.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.

For information on translations, please e-mail rights@apress.com, or visit www.apress.com.

Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales.

Any source code or other supplementary materials referenced by the author in this text are available to readers at www.apress.com/9781484222041. For detailed information about how to locate your book’s source code, go to www.apress.com/source-code/. Readers can also access source code at SpringerLink in the Supplementary Material section for each chapter.

Printed on acid-free paper

To my beloved sons, Georgia and Diego. You are the light of my life!

Contents at a Glance

About the Author

Flavio Morgado is a food engineer with a master’s degree in food science and technology. He is also a VBA professional developer, a technical writer, an English to Brazilian Portuguese technical translator, and a professor at UNIFESO – Centro Universitário Serra dos Órgãos in the city of Teresopolis in Rio de Janeiro, Brasil.

He has written more than 30 books (and translated an equal number) — all published just in Brazil. Flavio lives in Teresopolis; when he is not teaching, writing, or developing a love of something (or somebody…), he is running or riding his mountain bike throughout the Teresopolis Mountains, followed by his 11 dogs (2016’s dog count).

About the Technical Reviewer

Fabio Claudio Ferracchiati is a senior consultant and a senior analyst/developer using Microsoft technologies. He works for BluArancio (www.bluarancio.com). He is a Microsoft Certified Solution Developer for .NET, a Microsoft Certified Application Developer for .NET, a Microsoft Certified Professional, and a prolific author and technical reviewer. Over the past ten years, he’s written articles for Italian and international magazines and coauthored more than ten books on a variety of computer topics.

Acknowledgments

This book shows how to improve worksheet applications using Visual Basic for Applications (VBA). A great part of it was inspired or is based on content and knowledge available for free on the Internet. So, I like to thank the existence of these VBA Internet sites (in alphabetical order):

• Better Solutions: www.bettersolutions.com/

• Excel Matters: http://excelmatters.com/

• ExcelVBA: http://excelevba.com.br/

• Mr. Excel: www.mrexcel.com

• Microsoft System Development Network (MSDN): https://msdn.microsoft.com/

• Ozgrid: www.ozgrid.com/VBA/find-method.htm

• Pearson Software Consulting: www.cpearson.com/

• Ron de Bruin Excel Automation: www.rondebruin.nl/win/section2.htm

• StackExchange: http://stackexchange.com/

• StackOverflow em Português: http://pt.stackoverflow

• StackOverflow: http://stackoverflow

• VB-fun.de: www.vb-fun.de/

And thanks for the existence of these nutrient Internet sites (in alphabetical order):

• Agricultural Research Serving of United States: www.ars.usda.gov

• EatingWell: www.eatingwell.com/

• Food and Agriculture Organization for the United Nations: www.fao.org

• National Heart, Lung, and Blood Institute: www.nhlbi.nih.gov

• The Dash Diet Eating Plan: dashdiet.org

• Wikipédia: www.wikipedia.com

I also want to thank Microsoft and all the people on the Microsoft Excel development team for giving us Excel—a superb piece of software that is versatile and powerful. As a professional developer, I know how difficult it is to produce something so good, even though it is not perfect, but what is? Please Microsoft, receive my most profound respect and compliments.

Introduction

This book was created to teach you how to use Visual Basic for Applications (VBA) to automate worksheet applications.

It is a code book that was written to teach everyone, including people with zero experience in programming and people with decent programming knowledge, how to use and apply programming techniques to better interact with the users of your Microsoft Excel solutions in a more professional way. It uses some ready-made worksheet applications as practical examples of how you can produce solid, precise, and reliable worksheet applications based on VBA programming.

First I’ll introduce you to the VBA environment and the language structure and show you some basic examples that will take you on a consistent journey through the Excel object model. All the proposed examples use VBA to teach you how to interact with the Excel object model and its many properties, methods, and events.

As a basic strategy to teaching Excel VBA programming, this book uses the VBA Immediate window to first test each proposed Excel feature before showing how to use it in a code procedure. It is full of programming examples whose complexity grows from the book’s beginning to its end. This means it was written to be read one chapter at a time, with each chapter using the knowledge of previous chapters to provide a jump on your programmer skills.

My teaching strategy is to show a UserForm interface or code procedure step-by-step and to comment on all its instructions, one at a time, to give you a better understanding of how the VBA code can use good programming techniques to produce the desired result, with clear, concise, and reusable code.

What’s in the Book

This book is divided into 11 chapters, each one approaching Excel VBA programming with a new complexity. To get a big picture of what you will find inside it, here is a summary of each chapter:

• Chapter 1, “Understanding Visual Basic for Applications (VBA),” is intended to show you the VBA metaphor, including how to use VBA integrated development environment (IDE) and the VBA language structure. It is a basic chapter to show you a first approach to VBA and a programming language.

• Chapter 2, “Programming the Microsoft Excel Application Object,” touches on the first programmable object in the Microsoft Excel object model hierarchy: the Application object, which represents the Microsoft Excel application window, with some of its main properties, methods, and events. In this chapter, you will learn about the FileDialog, GetOpenFileName, GetSaveAsFileName, and OnTime methods; when the Application object events fire; and how to use a Class module to watch and/or control whether a worksheet tab name can be changed, as a first approach to producing VBA objects.

• Chapter 3, “Programming the Microsoft Excel Workbook Object,” talks about the second layer of the Microsoft Excel object model, which represents the Workbooks collection and contains all the open Workbook objects inside the main Excel window. You will learn about how and when the Workbook object events fire and will see the VBA UserForm and its controls, learning how to use the ListBox control and its interface (properties, methods, and events) to interact with the Workbook object using VBA code.

• Chapter 4, “Programming the Microsoft Excel Worksheet Object,” touches on the third object level in the Excel object model hierarchy: the Worksheet object, which represents the sheet tab in a Excel workbook file. It also shows how its programmable interface is composed (it properties, methods, and events). In this chapter, you will use again a VBA UserForm to learn how to add, delete, copy, move, rename, sort, and change sheet tab visibility inside a workbook file. You will also learn the many ways (and the preferable one) to reference sheet tabs in the VBA code and how to control the “cascade events” phenomenon that happens with VBA objects.

• Chapter 5, “Programming the Microsoft Excel Range Object,” talks about the deepest object inside the Excel object model hierarchy: the Range object, which can represent any number of cells inside a Worksheet object. Using another UserForm interface, you will learn how to programmatically define the cell addresses that compose any selected range, how to use VBA to name a range (using the Names collection), how to use the VBA Collection object, and how to produce a similar interface to the Excel Name Manager interface using VBA, improving the Excel interface by allowing you to change the range name visibility inside the workbook file.

• Chapter 6, “Special Range Object Properties and Methods,” expands your knowledge about the Range object by covering the Cells and CurrentRegion properties and the End, OffSet, Find, AutoFilter, Sort Copy, and PasteSpecial methods, using again the UserForm approach. At the end of this chapter you are presented with the frmFindFoodItems UserForm that uses most of this knowledge to find food items in the USDA food table using different search criteria (by food item name or nutrient content).

• Chapter 7, “Using Excel as a Database Repository,” presents you with a programmable approach to implementing a database storage system to store worksheet data as database records in unused worksheet rows, based on a data validation list cell and range names. This chapter uses all the knowledge gathered so far to produce a standard code module full of procedures that use module-level constant values to define the database parameters, allowing you to adapt it to any worksheet application design.

• Chapter 8, “Creating and Setting a Worksheet Database Class,” expands the database code module to a Class module that uses range names to store the database properties inside unused worksheet rows. It defines the SheetDBEngine class interface, showing how to implement its properties, methods, and events. To allow you to easily use the SheetDBEngine class, this chapter also presents the frmDBPRoperties UserForm, which was produced as a database wizard, to help implement the database storage system on any worksheet application.

• Chapter 9, “Exchanging Data Between Excel Applications,” answers important questions regarding how to programmatically update worksheet-based tables from where the worksheet application gathers its data. It teaches how to update the USDA worksheet to any version released by the ARS-USDA web page, using either a simple, silent procedural approach or a UserForm that reacts to the updating process, finding food item name inconsistencies between two releases of SRxx.accdb or SRxx. mdb Microsoft Access database nutrient tables. You will be also presented with the frmManage UserForm to allow mass operation on the worksheet database so you can delete and save recipe nutrient data and export and import recipes, using VBA automation.

• Chapter 10, “Using the Windows API,” takes your VBA knowledge gathered so far in this book to the next level by teaching you how to understand and use the Windows application programmable interface (API), based on dynamic linked libraries (DLLs) and C++ procedures. The API can be declared and called from within a VBA project. In this chapter, you will learn how to implement a Timer class to create programmable timer objects and how to change the UserForm appearance by removing its title bar; adding a resizable border and minimize, restore, and maximize buttons; and adding transparency and creating a fade effect. You’ll also learn how to animate a UserForm when it loads and how to apply a skin effect to change the UserForm shape.

• Chapter 11, “Producing a Personal Ribbon Using RibbonEditor.xlam,” uses the RibbonX VBA add-in developed by Andy Pope as free software to produce a personalized ribbon with tools that interact with your worksheet application, giving it a professional appearance.

• The afterword is a brief testimony of the path used to write this book, with my insights about how I imagined it and created it step-by-step, with trial-and-error experimentation as I learned the Excel object model.

This Book’s Special Features

Programming Excel 2016 with VBA was designed to give you all the information you need to understand how to replicate a behavior, insert a formula, define an interface, and so on, without making you wade through ponderous explanations and interminable background. To make your life easier, this book includes various features and conventions to help you get the most of the book and Excel itself.

• Steps: Throughout the book each Excel task is enumerated in step-by-step procedures.

• Commands: I used the following style for Excel commands: Conditional Formatting button in Styles area on the Home tab of the ribbon (this mean you must click the Conditional Formatting button that you find in the Styles group of the Home tab).

• Menus: To indicate that you click the File menu and then select Save, I use File ➤ Save.

• Functions: Excel worksheet functions appears in capital letters and are followed by parenthesis: IF( ). When I list the arguments you can use with a function, they will appear in a bullet list of items, using the same order that they appear inside the function arguments list to explain the meaning of each one.

• Rows, columns, cell address, ranges, and sheet names: Excel rows, columns, cell address, range names, and sheet names appear using an Arial font to detach them from the text.

This book also uses the following box to call attention to important (or merely interesting) information:

■ Attention The Attention box presents asides that give you more information about the topic under discussion. These tidbits provide extra insights that give you a better understanding of the task at hand, offer complementary information about the issue that is being currently discussed, or even talk about an unexpected Excel behavior regarding a given task.

Web Site Extras

All the examples presented in this book are available at www.apress.com/9781484222041 as ZIP files for each book chapter. In addition to the example workbooks or worksheet applications, I’ll post any updates, corrections, and other useful information related to this book.

Your Feedback Is (Very) Important!

Before you continue reading, I would like to say that your opinion is important to me. I really don’t know how many of you will write to me to give any feedback, but I hope I can answer everyone and, whenever possible, resolve any questions or problems that arise. Since I have many other duties, sometimes it may take a little while so I can answer you, but I promise to do my best. Please feel free to write to me at the following e-mail: flaviomorgado@gmail.com

Understanding Visual Basic for Applications (VBA)

This chapter will teach you how to program Microsoft Excel using Visual Basic for Applications code procedures. It will show you how to interact with the VBA integrated development environment (IDE), show how VBA programming code works, and give lots of examples. This introduction is for people who do not know anything about VBA and want to get started. If you already have some experience, you can skip to Chapter 2.

You can obtain all the procedure code in this chapter by downloading the Chapter01.zip file from the book’s page at Apress.com, located at www.apress.com/9781484222041, or from http:// ProgrammingExcelWithVBA.4shared.com.

What Is Macro Code?

There was a time in computer usage that if you needed to accomplish a series of successive commands in software, you could use the appropriate program syntax to type the menu commands to follow, one command per row, and then make the program execute them, row by row. In the DOS age of the early 1980s, the spreadsheet program called Lotus 123 called this method a macro, and since then, every time a program tries to allow the user to implement such a resource to execute any desired number of successive menu commands, the convention is to say that the program is following a macro code.

The first versions of Windows and all Microsoft Office applications (including Microsoft Excel) could implement this sort of automation by recording successive series of actions performed on the interface using the keyboard or the mouse.

Until 1994 when Microsoft Excel was on version 3.0, each Microsoft Office application had its own way to store its macro codes, meaning that these codes were not interchangeable between Office applications. In other words, Word has its own set of commands, PowerPoint had another set, and Excel had yet another one. At this time you needed to be very specialized to read and understand each Microsoft Office application macro code.

Everything changed in 1995, when Microsoft released Microsoft Visual Basic 4; its IDE used the VBA language and made it part of all Microsoft Office 6 applications. From this time on, all Microsoft Office applications were capable of being programmed using a single language, allowing all applications to interact with each other. Even though this code was produced with VBA as a true programming language, the term macro code stuck to this sort of application automation and continues to be used today.

Electronic supplementary material The online version of this chapter (doi:10.1007/978-1-4842-2205-8_1) contains supplementary material, which is available to authorized users.

Flavio Morgado 2016 F. Morgado, Programming

Although you can consider Excel macro code to be any kind of code automation created to interact with Excel and its environment, you can divide the code into two types of VBA code.

• Excel macros: The VBA code created by Excel itself when you activate Excel macro recording and execute any successive actions on its interface

• VBA programming code: The code you create by hand to implement the same automation, but with more control and many times with more efficiency

In this book I will teach you how to understand and create your own VBA code procedures so you can take greater control of your worksheet applications.

The VBA Environment

Before you begin to learn the Visual Basic for Applications language, you must acquaint yourself with the VBA IDE; this is the place where you can create and test the VBA code of any Microsoft Office application. There are two ways to open the VBA IDE.

• By going to the Microsoft Excel Developer tab and then clicking the Visual Basic button, as shown in Figure 1-1

• By pressing Alt+F11 in any Microsoft Office application

Figure 1-1 shows the Developer tab on the Excel ribbon with the Visual Basic command button.

Figure 1-1. This is the Excel Developer tab, where you will find, among other tools, the Visual Basic command button to activate the Visual Basic IDE

To show the Excel Developer tab, follow these steps:

1. Click the Excel File tab and select Options to show the Excel Options dialog box.

2. Select the Customize Ribbon option.

3. In the right list box, check the Developer tab (Figure 1-2).

4. Click OK to close the Excel Options dialog box.

Figure 1-2. To show the Developer tab on the Excel ribbon, select File ➤ Options, click Customize Ribbon, and check the Developer option in the right list box

Figure 1-3 shows the Visual Basic IDE that you can activate by pressing Alt+F11 or by clicking the Visual Basic command on the Excel Developer tab.

■ Attention You can turn on the visibility of the Project Explorer, the Properties window, and the Immediate window using the appropriate commands in the Visual Basic View menu item.

Modules: The VBA Documents

VBA works this way on Office documents: each document created by any Microsoft Office application has one specific VBA object attached to it called a code module. It is almost impossible to dissociate the object from the code module, and if this happens (which is rare but possible), the file becomes corrupted and unusable until you fix it by deleting the offending object.

Excel has the ability to open workbook files, which are a special kind of file made up of one or more worksheets (called Sheet1, Sheet2, and Sheet3). Indeed, each new file created by Microsoft Office 2003 or later versions has by default three blank worksheets (although you can configure Excel to create new workbooks with 1 to 100 blank worksheets).

■ Attention To configure the number of blank worksheets a new Excel workbook (or Excel file) has, select File ➤ Option, select “Include this many sheets” option, and indicate how many worksheets you desire. Note, however, that every workbook must have at least one worksheet inside it.

Figure 1-3. This is the Visual Basic IDE that you use to write and follow VBA procedures and codes, with the Project Explorer, the Properties window, the Immediate window, and the Code window (for Book1, Sheet1) visible

From VBA’s point of view, each Excel object has its own code module: one for the entire workbook (it is the last object on the Microsoft Excel Objects branch of the Project Explorer tree, named ThisWorkbook) and one for each worksheet inserted by default on the workbook, named with the same worksheet name (Sheet1 to Sheet3 on a default workbook with three blank worksheets). They are always positioned at the beginning of the Microsoft Excel Objects branch of the Project Explorer tree (Figure 1-4).

Figure 1-4. Every Excel file, or Excel workbook, has at least one code module associated with the workbook (named ThisWorkbook) and one code module for each worksheet, having the same name of the sheet tab. They are all shown on the Project Explorer tree

To see the VBA code module associated with each default Excel object, double-click the code module in the Project Explorer tree. Figure 1-3 shows the Sheet1 code module, while Figure 1-5 shows the ThisWorkbook code module opened in the VBA IDE.

Figure 1-5. This is the VBA code module associated with the Excel workbook file. By default it is called ThisWorkbook, and every Excel file has just one of them

CHAPTER

Standard and Class Modules

Although no Excel object can be dissociated from its code module, you can create independent code modules that are not associated with any object using the VBA Insert ➤ Module and Insert ➤ Class Module menu commands. Figure 1-6 shows that after you execute VBA Insert ➤ Module, a new Module branch of independent code modules is created inside the Project Explorer tree, with the new Module1 code module already selected in the VBA interface.

Figure 1-6. This is the VBA IDE after a new independent code module called Module1 was created using the VBA Insert ➤ Module menu command

■ Attention You can change the focus from one code module to another by double-clicking the Project Explorer tree or by using VBA Windows menu command to select it from among any open code module windows.

Note that whenever you select any Excel object in the VBA Project Explorer tree, all its properties are shown in the Properties window, even if the code module is closed. Later in this book I will talk about some interesting code module properties associated with just the VBA IDE or with the object itself (properties associated with the worksheet or workbook object).

This VBA structure of different code module windows is part of any Excel macro-enabled workbook, even if you don’t use them! They are the documents that can be manipulated just by the VBA IDE, and it is where all the action will occur to control the automation of your Excel solution.

■ Attention To delete any module or class module inserted in the VBA structure of an Excel file, right-click its name on the Project Explorer tree and select Remove <Module Name> in the pop-up menu. You will be prompted to export the code module code before you delete it from the workbook structure.

Class Modules

Class modules are a special type of code module that allows the creation of a programmable “object.” Using Class modules, you can trap other existing VBA objects (like the Excel Application object, UserForm, and so on), create your own objects, define behavior using Property procedures and methods represented by Public and Sub procedures, and raise events (automatically respond to user actions). Consider a Class module as a code repository that can be reused, creating many instances of the class for the same purpose, where all instances share the same base code. The Class module is the core module of object-oriented programming in VBA, and you will see it in action later in this book.

The VBA Language

Like any other programming language, VBA executes individual statements one at a time from the first row after the procedure declaration to the last row.

You should strive to write procedure code using VBA strict syntax rules with one statement per row. The shorter the procedure code is (the fewer rows it has), the faster it executes and the easier it is to understand.

To know how to write VBA code, you must understand its syntax for variable declarations, its instructions, and its functions.

Procedures: The VBA Code

Procedures are the heart of any programming language. They are responsible for executing the actions you need to grant a given functionality to your application.

You use VBA code modules to write the procedures that must be executed; there are three types of procedures:

• Function procedures: These can return a value when finishing execution.

• Sub procedures: These can’t return a value.

• Property procedures: These are a special pair of procedures with the same name that can implement an object property.

For now we will stay with the concept of Function and Sub procedures. Property procedures will be addressed later in this chapter.

Using Function and Sub Procedures

You may ask why Function and Sub procedures exist, and my answer is that they are a holdover from the very first programming language. They allow a programmer to divide the executing code into reusable parts. The main code is executed by one procedure (Function or Sub), while any reusable can is executed by a Sub procedure, thus reusing its code.

For our usage, let’s just stay with this simple definition: use a Function procedure whenever you want to return a value, and use a Sub procedure whenever you want to execute any necessary and successive programming steps without returning any value (and this Sub procedure eventually can be reused by other procedures).

Both Function and Sub procedures have specific syntax rules for any VBA code module: a begin statement that indicates its scope (Public or Private), its name, its argument list (if any), the type of returned value for Function procedures, and an End statement.

The following VBA code fragment declares a simple Function procedure named FindFoodITem( ) (note that it has a return value declared as Boolean):

Function FindFoodItem( ) as Boolean [Statements]

FindFoodItem = <FunctionResult> End Function

■ Attention In this book, everything that appears inside the < > characters means the name you must give to the procedure or argument it represents.

The following is another VBA code fragment declaring a Sub procedure named FindFoodItem( ) (note that it does not return a value):

Sub FindFoodItem( ) ...

End Sub

■ Attention In the same VBA code module there can be only one FindFoodItem( ) procedure, declared as a Function or Sub procedure.

The following is the complete VBA syntax necessary to declare a Function procedure (optional parts of the Function declaration are between brackets):

[Public | Private | Friend | Static] Function <FunctionName> ([Optional] [Arg1[ [as Type],...) [As<Type>] [Statements]

<FunctionName> = <FunctionResult> End Function

In this code:

[Public | Private | Friend | Static]: These are VBA keywords to specify the scope of the Function procedure. Note that they are between brackets, meaning that they are optional. If you don’t use a VBA keyword, the Function will be considered Private, meaning that it can be accessed only by the procedures inside the code module where it belongs. If you use the keyword Public to declare a Function procedure, it will be capable of being accessed from other procedures in any other code module of your workbook application.

■ Attention The Friend keyword is used only on Class modules to create procedures that are public to all Excel objects on the same workbook while it is private to the code. The Static keyword indicates that all variables declared inside the Function procedure will keep their values between function calls.

<FunctionName>: This is the name you want to associate with the Function procedure. It must begin with a letter and have no spaces or reserved characters. A good programming practice for Function names is to use a clear name that indicates what it executes. It must be made up of concatenated names, where each name must begin with a capital letter like Function FindFoodItem( ).

[Optional] [Arg1]: Both Function and Sub procedures must be followed by a pair of parentheses, which may contain one or more declared arguments that the function can receive. These arguments are the values upon which the function will operate. VBA allows you to pass optional arguments if you precede them with the Optional keyword (meaning that you are not obliged to pass them to the procedure). Once one argument is declared as Optional, all others that follow it must also be declared as Optional

[As <Type>]: Arguments for Function and Sub procedures, as the values returned by a Function procedure, can be of a specific type. They can be an integer or real number, a text string, a date, a logical value, or an object. If you do not specify the type expected to be received by an argument or returned by a Function, the type will be considered as the Variant data type, which is a special kind of VBA data that is polymorphic, meaning it can represent any data type.

End Function: This must be the last function statement indicating to VBA where the code procedure ends.

To declare a Sub procedure, you use the following syntax. Note that it is almost identical to the Function procedure declaration, except it doesn’t return a value (it doesn’t have the [As Type] part of the Function declaration) and has an End Sub statement to indicate its finish.

[Public, Private] Sub <SubName> ([Optional] [Arg1[ [as Type],…) [Statements] End Sub

Calculating Age in Years

Let’s try to write a simple VBA procedure to calculate the age in years of any person. How we can do that? We need simple basic information: the person’s date of birth! Since your computer always has the current date, we can use it to count the number of days between these two dates (current date minus date of birth) and do some math to express the result in years.

Before we try to create this simple procedure, you need to know a basic concept regarding how VBA treats date values.

To Windows—and all its applications—any date is just a consecutive counting of the number of days since 01/01/1900. The first day of the 20th century is considered as day 1, and any later date is a consecutive day counting from it (earlier dates are negative values). I am writing these words on 02/17/2014, and this date is considered by Windows as day 41,687, meaning that it has been 41,687 days since January, 1, 1900.

■ Attention You can easily get the number for any date by typing it in any Excel cell and changing the cell format from Date to General number.

By subtracting two different valid dates, you will receive the number of days between the two dates. Dividing this result by 365 days per year, you will get the difference in years, right?

■ Attention For your information, a valid Date value is one that has no more 30 days in April, June, September, and November; has no more than 29 days in February on lap years (28 days in normal years); has no more than 31 days in January, March, May, July, August, October, and December; and has a month value between 1 and 12.

The next Function procedure code calculates any person’s age in years by receiving the person’s date of birth as an argument to the procedure:

Function AgeInYears(DateOfBirth)

AgeInYears = (Date - DateOfBirth) / 365 End Function

■ Attention Extract the AgeInYears.xlsm macro-enabled workbook from the Chapter01.zip file to test this function procedure.

To build this AgeInYears function, follow these steps:

1. In the VBA interface of any Excel worksheet, choose the Insert ➤ Module menu command to create a new standard code module.

2. Make the VBA Properties window visible by executing the View ➤ Properties Window menu command.

3. In the Property window, type basAgeInYears for the Name property of this new code module.

4. Insert in the basAgeInYears code module a new Public Function procedure by executing the Insert ➤ Procedure menu command. In the Add Procedure dialog box, type AgeInYears as the procedure name and select Function on Type and Public on Scope.

5. Click OK to create the Function AgeInYears( ) procedure structure in the basAgeInYear module (Figure 1-7).

Another random document with no related content on Scribd:

overcomes chronic muscle spasm as traction The principle underlying treatment by traction is exceedingly simple, but there are numerous ways and mechanical expedients for effecting it. In the lower limb, whether this shall be done by anterior suspension, by weight and pulley, by elastic contraction, or by some of the more complicated splints, matters little so long as it be efficiently made. Of all these methods it may be said in general the simplest is the best. In the upper extremity traction may be made by similar methods with the patient in bed, or the patient may be allowed to rise and be about with a weight hanging from the elbow or some simple expedient of this kind.

The method of traction is one to be combined usually with further protection, by which not only longitudinal but lateral displacement maybe overcome. This suggests the use of splints in addition to mere traction methods.

It is not always possible to put in operation at first that method which we may prefer a little later, as swelling is usually so pronounced as to make it advisable only to put the parts at rest and hasten absorption. The same is true of hemorrhage. In rarer instances it may be a question as to whether the distal parts may undergo gangrene from the disturbance of circulation. These are matters to be duly regarded before the later and more complete dressing. Mechanical aids, usually in the shape of splints, are therefore necessary. The physiological rest which it is so necessary to ensure will lead to a certain wasting of muscles and stiffening of joints, which are only temporary, but which by no means lessen disability when splints are removed. That splint is best for a given case which best fits it and permits the surgeon to carry out its peculiar indications. The writer is opposed to manufactured splints, as they seldom fit the part. This can be obviated by packing cotton or other compressible material into the splint. For temporary purposes they will frequently suffice. For fixed dressing, however, it is preferable to make a splint which shall fit the limb to which it is affixed. Immobilization is difficult of accomplishment and at many points impossible. Thus in fracture of the ribs or clavicle it is impossible to avoid a certain amount of motion with each respiratory effort, even though an uncomfortably tight dressing be applied.

Splints are made of various materials, metal, wood, various compositions hardened in molds, plaster of Paris, or some of its substitutes, i. e., glue, soluble glass, or a composition like one made of equal parts of powdered starch and fine isinglass, added to a solution of potassium silicate, this being allowed to stand for several days, after which a little fine boric acid powder is added; when this is painted over gauze dressings it solidifies and forms a light and rigid splint. There is one objection to all methods which comprise a solution that hardens slowly—that is, that during the time required for the purpose redisplacement may occur It is not advisable to dress a recent fracture in a wet pasteboard splint or in such a composition as that mentioned above. Later, when a certain amount of consolidation has already occurred they may serve a useful purpose.[38]

[38] Jenkins’ packing, such as is used on some engines, has been recommended by Spotswood as a substitute for plaster-of-Paris bandages, its advantages being that it is not affected by any antiseptic washes as a plaster dressing would be, that it is lighter, and that by placing it in hot water it can be molded to assume the shape of the limb.

There are two methods of using plaster of Paris: one is gauze bandages sprinkled with it, rolled, and kept ready for use, to be placed in water at the time of their employment. A limb may be enveloped in these, after being covered with a layer of wadding or some other protective material, by which the plaster shall not come in actual contact with the skin. It is also a good plan to place a strip of tin or pasteboard along the exposed surface of the limb, over which the surgeon cuts to remove the splint. Thus one may avoid any danger of injuring the skin with the point of the knife. It is also a good plan to make at least a part of this cut before the plaster has sufficiently hardened, i. e., to do most of the work, leaving perhaps a layer or two of gauze to be cut through some time later. It is necessary to impress the fact that when a quickly hardening fixed dressing is used approximation should be ensured by the greatest attention, maintaining it until the splint is so hardened that redislocation is impossible. Another method of using plaster of Paris is by sopping strips of surgeons’ lint, ordinary canton flannel, or almost any other similar material, in plaster-of-Paris cream, then molding these to the injured limb, maintaining the same rigid

precaution as to the proper position of the same while the splint hardens. In this way a splint can be adapted to the part, and, at the same time, made removable, permitting as frequent access to it as may be desired.

COMPOUND FRACTURES AND THEIR TREATMENT.

As already stated, it is the communication of fractured bone surfaces with the external air which makes a fracture compound in the strictly surgical sense. This may occur through a minute and tortuous opening or through a large and extensive wound. Although the communication is with the atmosphere the danger comes not so much from germs floating in the air as from those on the surface of the body and within the pores of the skin, or else from foreign material admitted through the external wound. Obviously the great danger is of septic infection. Whether the tissues may prove more or less susceptible, and thus resist or break down, cannot at the outset be foretold. This leaves but one imperative ride to follow, to act in every instance as though serious injection had occurred and to take precautions accordingly. Even a small puncture made by a spicule of bone may permit germs to be withdrawn into the tissues as the bone is replaced. If, then, the surgeon seals such a puncture he necessarily takes the chances and must abide the result. Whether he shall do this or not will depend upon the patient and the injury. At all events, the site of puncture should be carefully cleansed and disinfected and the case so dressed that it may be carefully watched. Complete sterilization of every particle of exposed tissue is absolutely necessary, and for this purpose hydrogen dioxide or some of its later substitutes will prove effective. A protruding splinter of bone should be removed with cutting forceps, unless the wound must be enlarged as a part of the treatment of the fracture. In most instances it will be safer to pursue this course, i. e., to extend the wound which makes the fracture compound, to a degree permitting thorough exploration and cleansing. Not infrequently fragments of bone will be found, which when nearly or completely detached should be removed. Such a free opening permits also of wiring, or other means of fastening together bone ends, by which apposition

may be more perfectly secured. A compound fracture which has been long unattended may be safely assumed to be septic. Here free incision, with cleansing and ample drainage, will be a far safer course than non-compliance with the general rule.

Compound fractures of the skull are nearly always depressed fractures, and practically always call for operation. Their proper treatment will be dealt with when considering Injuries to the Head. A fracture of the ribs may be made compound by penetration of a sharp bone end, and such injury to the lung as may permit air to escape into the pleural cavity Such a pneumothorax may be followed by a hemothorax and hydrothorax, and these perhaps by empyema. Compound fractures of the pelvis are not infrequently complicated by perforation of the bladder or bowel, or rupture of the urethra, or some other serious visceral injury which may determine their fate. Compound fractures are difficult of treatment because they entail frequent changes of dressing and prevent the use of desirable splints. These fractures are also sometimes so serious as to necessitate amputation, which may be necessitated either by such comminution of bone as to make repair impossible, or such injury to vessels as may determine gangrene. If the circulation can be shown to be sufficient, either at the time or perhaps by delay of a few hours or a day, a limb may be saved by the resection of one or both bones, which in pre-antiseptic days would have required amputation.

The surgeon does not always see these cases in their recent or fresh state. He may be called to a case complicated by suppuration, cellulitis, and sepsis. Here though amputation may be required he may still delay it, hoping to improve local conditions, and thus to make it more promising, or he may have to resort to various expedients, such as suspension with constant irrigation, or temporary packing with yeast, in order to justify any further attack upon the parts already involved.

In the treatment of compound as of simple fractures we should never lose sight of the dangers of too tight bandaging and of pressure sores. I have seen both these lead to gangrene, with its necessary mutilation, in cases where the attendant has forgotten the proneness of injured parts to swell, and has either not allowed for

this within the dressings or has not atoned for it in time when it has already occurred.

In the treatment of all these cases the operator should never forget the medicolegal aspects of such a case nor the necessity for constant attention and caution on his part. He should remember that his minutest precautions will often be disobeyed. He may, however, be cheered by the fact that only in cases of carelessness will he incur legal responsibility.

SPECIAL FRACTURES.

Fractures of the skull and of the vertebræ will be considered under the respective headings of Injuries to the Head and to the Spine.

FRACTURES OF THE NOSE.

The nose is the most frequently broken of all the bony parts about the face. One nasal bone or both may be broken, and each may be separated from its bony supports as well as from the other The fracture may be compound in either direction, most frequently so into the nasal cavity, as a result of which infection may as easily take place from within as from without. The cartilages may also participate in the injury.

The injury would be easy of recognition were it not for the amount of swelling that often accompanies it. The signs are mobility and crepitus, with more or less deformity. So long as the nose can be grasped between the fingers recognition of fracture is easy. If swelling prevents this an instrument or the finger can be passed into one nostril and combined manipulation practised. There is generally more or less bleeding from the nose, and sometimes considerable emphysema. Swelling and ecchymosis are also often pronounced. This will all subside under cool and soothing applications. The most important indication is to replace the nose and hold it where it should remain. The difficulty is increased by the efforts which the patient instinctively makes to dislodge clot or secretion. The importance of accurate reposition is in some cases sufficient to justify an anesthetic

and instrumental help. This will permit of the application of such force as may be necessary to elevate or to shift fragments, while a gutta-percha splint may be molded upon the outside, or a sterilized pin or needle made to transfix the nose from one side to the other (Mason), passing behind the fragments and through the septum in such a way as to keep it from dropping backward. A good plan is to introduce a tube into each nostril, perhaps a piece of silk catheter, around which a certain amount of gauze can be packed, and which can thus be used as an internal splint, while on either side and externally a little roll of gauze is held in place by adhesive plaster crossing the cheeks. The operator should take as much pains to see that the septum is in its original position as in attending to outside and cosmetic effects. The septum can be controlled by a pair of forceps.

A nose properly held in place will heal within a few days, to a point requiring little if any support. A transfixion pin should not be needed, if used, for more than four or five days. An internal splint should be removed each day, so that the nose may be sprayed with cleansing solution (Dobell’s) and retained secretions removed.

The disfigurement resulting after this injury is dropping in at the root of the nose, constituting the so-called saddle-nose defect. Such disfigurement as results can be later atoned for by subcutaneous injection of paraffin. (See chapter on Surgery of the Face.)

FRACTURES OF THE SUPERIOR MAXILLA, WITH OR WITHOUT OTHER BONES OF THE FACE.

The more protected portions of the upper jaw are rarely fractured, save by extreme violence. The alveolar process, with one or several teeth, may be partially or completely detached. Such fractures are compound, and after replacement need antiseptic mouth-washes as well as other attention. Usually the teeth in the fragment can be utilized for the purpose of fastening it back into place by means of the uninjured teeth, retention being secured by wire or waxed silk. Extensive detachment may necessitate sutures through drill holes. The lower jaw can usually be utilized as a splint for the upper by binding the jaws firmly together and feeding the patient on fluid food.

When one or two teeth are loosened or displaced it will often be possible, if they can be promptly secured, to successfully reimplant them in their sockets. Both the sockets and the teeth should be thoroughly cleansed. After replacement it will be necessary only to ensure absolute rest and retention in position.

In regard to other facial bones there is no injury which may not occur, as the result of direct violence. The zygoma and the malar bone may be broken away, or the entire collection of facial bones may be loosened from their connection with the bones of the skull proper The margins of the orbit, or its walls, may also be injured, and the sinuses opened, with perhaps more or less entrance of foreign material. These fractures are generally compound and are accompanied sometimes by injuries to the soft tissues. It becomes then a question not merely of cosmetic result, but of avoiding infection and saving life. The latter is the more important, and measures should first be directed to that object. Satisfactory results can be attained by drilling and holding bone fragments together with tendon or other sutures, and by neatly trimming and cleaning wounded surfaces and bringing them together. Subcutaneous sutures should be used for this purpose.

FRACTURES OF THE INFERIOR MAXILLA.

This bone is broken nearly as often as the nose, and almost invariably by direct violence. Here, as in the upper jaw, there may be trifling or serious fractures of the alveolar process, which should be treated on the same principle as above set forth. Fractures of the rami occur more often in those parts which are occupied by teeth, or from which teeth have dropped out by senile changes, the jaw being weakened at these locations. The most frequent seat of fracture is near the middle line. Fractures of the ascending ramus and of the upper processes are rare. Double fractures are not infrequent, the lines of separation being rarely symmetrical. The gum and the skin are often torn and the majority of these fractures are compound. The bone is considered to be weakened at the dental foramen; at all events it often yields in this vicinity. By fracture with much displacement posterior to this opening the inferior dental nerve may

be injured or torn. The condyle, after extreme violence, has been known to have been driven up into the cranial cavity through the base of the skull. Gunshot fractures are nearly always comminuted (Figs. 281, 282 and 283).

Use of silver wire in fixation of fragments by utilizing the teeth.

Bandage and splint for fracture of lower jaw. (Bryant.)

The signs of fracture of the lower jaw are unnatural mobility, crepitus, displacement, pain, and loss of function. No bone in the body is more easily investigated by sight and touch, and recognition of these fractures is usually easy. Pain is provoked by attempting to move the jaw, even in talking, and depends on the extent to which the inferior dental nerve is injured. Irregularity in the line of the teeth will sometimes permit recognition. These fractures furnish excellent illustrations of the effect of muscles in producing displacement. Those of the tongue and the floor of the mouth, as well as the anterior muscles of the neck, will pull the fragments in various directions, according to the direction of the line of fracture and its location. This displacement may be trifling or serious. These fractures are often compound, internally or externally, such injuries

constituting an unpleasant complication, but affording occasionally an opportunity for fastening fragments by drill or wire suture, which would otherwise require an opening to be made. In every instance antiseptic mouth-washes should be frequently used.

Treatment.

—The treatment is simplified when the dentition is good and regular so that the fragments may be fastened together with wire or waxed silk ligature around the adjoining teeth, and then fixation accomplished with a simple molded gutta-percha or plaster-of-Paris splint, by which the lower jaw is held firmly against the upper. Such a dressing is held in position by a fourtailed bandage (Fig. 283). A silk or wire loop, used for the purpose just mentioned, should include two teeth on either side of the fracture, for by constant tension the nearest tooth will soon loosen, and if this were next to the break the effect of such displacement would be injurious (Fig. 281). When the line of fracture is oblique there is often greater difficulty in adjustment.

While the simplest means by which the fragments may be kept in position are the best, there should be no hesitation in serious cases to resort to operative measures having for their purpose the insertion of wire sutures or their equivalent. These are inserted after drilling the bone at suitable points, and are introduced with a view to their subsequent removal, the ends being left projecting in order to facilitate this. In clean cases, where the incision is made in unbroken skin, the ends may be twisted short and turned in, previously to closing the wound. Such operative treatment is required when there has been a double fracture, the central fragment being badly displaced by groups of muscles which tend to pull it downward and backward.

A dentist should be consulted, as he may be able to make a mold and then construct a plate or interdental splint, by which a more perfect reposition may be effected.

Swelling, emphysema, ecchymosis, etc., may be treated in the usual way Irritation is likely to provoke free secretion of saliva; this may be combated by small doses of belladonna. Patients should be fed by fluid or thin semifluid food, and mouth-washes should be frequently used.

FRACTURES OF THE HYOID BONE.

The hyoid may be broken by direct violence, either locally applied or by forcing the head backward. Fracture of the bone itself is not so serious as the lesions which accompany or follow it, either hemorrhage or inflammation, with edema of the larynx, which may impede respiration or cause strangulation. Fracture produces difficulty in breathing, swelling, and pain on talking. It is doubtful if bony union is attained, but fibrous union answers equally well. The treatment consists essentially of physiological rest. Edema may necessitate tracheotomy, and dysphagia feeding by an esophageal tube or by the rectum. Should the fracture be compound, or should a fragment be displaced so as to be detected, it may be removed through suitable incision.

FRACTURES OF THE LARYNX.

This may be fractured by injuries of the same character as those which fracture the hyoid, except that it is more exposed to the direct violence of a blow, as from a baseball. In elderly people in whom calcification of the laryngeal cartilages has occurred fracture is more dangerous than in the young. Injuries which produce these lesions are of a serious nature, as prompt swelling, either from hemorrhage or edema, occurs and threatens respiration. For illustration a death occurred on the baseball field within a few minutes after reception of a blow upon the front of the neck with laryngeal fracture; the cause of death was suffocation due to swelling, which might have been averted if tracheotomy could have been performed. In the milder injuries of this kind much can be done with sprays of cocaine and adrenalin, to quiet laryngeal irritation and reduce vascularity

FRACTURES OF THE STERNUM AND RIBS.

Fracture of the sternum in childhood is exceedingly rare. In adults it may occur in connection with other injuries or as a solitary lesion. Such a fracture, of itself, would indicate in most cases excessive violence. It is usually more or less transverse, the periosteum being

rarely so torn as to permit of much escape of blood. Cases are recorded in which it has been broken in straining during the act of parturition. It is most commonly injured by compressing and crushing injuries.

Sternal fractures are followed by much pain, aggravated by deep respiration and made worse by pressure. Sometimes displacement can be made out, while crepitus may be detected with the stethoscope. Occasionally there is sufficient deformity to make the injury apparent at a glance.

Displacement should be reduced and apposition then maintained by a plaster-of-Paris jacket or other suitable apparatus. It is advisable in some cases to anesthetize the patient and to make a sufficient opening that instruments may be used by which fragments may be lifted or pried into place. This should be done under aseptic precautions.

Diastases or separations of ribs or cartilages from the sternum or from each other have essentially the dignity of fractures, are recognized by the same general signs, and are treated in the same general way. A cartilage may snap in the young, and in the old, when calcified, may break as would a bone or even a pipe-stem.

The ribs are usually broken in their lateral aspects, but rarely between the head and angle. They may be fractured by muscle action or by external violence, examples of the former being violent efforts at lifting or sneezing. Violence may be applied in so many ways that it is not necessary to specify them. Fractures may pertain to one or to several ribs in proportion to the extent and violence of the exciting injury. In some crushing injuries an entire section of the chest wall may be broken loose and depressed, this corresponding to a depressed fracture of the skull. Rib fractures are usually of themselves innocent, but may be made serious by complications, as when the pleura is torn, or an intercostal artery bleeds profusely, or when a jagged fragment of bone first scratches and then perforates a lung. This will lead first to the outpour of blood and then of pleuritic fluid, by which in a short time the lung will be separated from the chest wall. Should infection occur through the injured lung, i. e., entrance of germ-ladened air, then empyema may seriously complicate matters and later necessitate operation. Even the heart

has been injured, in several reported cases, by projecting fragments of bone. Gunshot fractures of the thoracic wall imply those features pertaining to every compound fracture, plus the injury possibly done to the lungs, heart, or mediastinal contents, such as hemothorax or pneumothorax.

The first and second ribs are so protected and the eleventh and twelfth so movable that by far the greater proportion of rib fractures pertain to the eight intervening ribs.

Symptoms.

—These are often vague, when but a single rib has been cracked through and not displaced, and comprise pain on pressure, as well as that provoked by deep breathing, coughing, and certain other movements. Should this pain be limited, or constant and made worse by pressure, fracture of the rib may be suspected. If auscultation crepitus can be heard, diagnosis is at once made. When abnormal mobility is unmistakable, or when by any means crepitus is elicited, the signs are positive. Sometimes the patient himself will recognize crepitus. This may be learned either by auscultation or by pressure with the flat hand over the affected area. Emphysema is an unmistakable evidence of fracture with perforation, while the signs of the presence of fluid in the chest cavity will also indicate fracture.

Treatment.

—Fracture of one or two ribs with displacement is ordinarily a matter of trivial import, the adjoining ribs acting as splints. It necessitates practically nothing but physiological rest, which may be best afforded by keeping the patient in bed, with firm compression around the chest, made either with a binder of strong cloth or a broad piece of adhesive plaster carried nearly around the body, or in more aggravated cases by a plaster-of-Paris jacket. In thin individuals the formation of callus can be recognized by the sense of touch. So soon as this is fairly formed displacement is less likely to occur and uncomfortable compression may be relaxed. Should there be external angular displacement this may be corrected by pressure. A projecting fragment which threatens to perforate should be cut away with bone forceps through a small incision, taking pains to permit as little air as possible to enter. If there be a traumatic pneumothorax the air should be removed with an aspirating needle. When it is evident that there is serious injury to

the chest wall and that air has already separated the lung from it (traumatic atelectasis) the parts should be freely exposed, to permit the rounding off of bone ends, the seizure of intercostal vessels, the cleansing out of the pleural cavity, with perhaps later wiring of fragments or else their complete removal and closure of the external wound with or without drainage, as may be required. If blood or air has already escaped into the pleural cavity the blood should be speedily removed. The same plan is advisable in fractures of the cartilages. Sedatives to check cough, e. g., heroine, are also indicated.

FRACTURES OF THE CLAVICLE.

The clavicle and the radius are the two bones most frequently broken, the former more often in the young, the latter in the elderly; the clavicle yields both to direct violence, as by blows on the shoulder, and that which is transmitted through the arm from the elbow or hand. For convenience of description the bone is divided into thirds, the most common location for fracture being near the junction of the middle and outer third. Save for epiphyseal separations the extremities of the bone are seldom broken. In spite of its subcutaneous position and its proximity to large vessels, compound injuries or other complications are quite uncommon.

The clavicle is the brace which keeps the shoulder proper from falling upon and around the thorax. Consequently when it is broken the shoulder tends to drop downward, forward, and inward, except in a green-stick fracture, while even then there may be some displacement in these directions. Deformity is usually easily recognized, one or other fragment projecting beneath the skin in such a way as to be easily palpated. There is enough spasm of cervical muscles to draw the head over toward the affected side, while there is loss of function in the affected arm. Pain is made worse by pressing the shoulder inward as well as by moving it in any direction.

In young children the bone is often broken with a minimum of displacement. Fracture of both clavicles is not so very rare. Trouble may occur later in the course of the case from pressure of exuberant

Treatment. callus upon nerves and even vessels. This is to be prevented by foresight and by careful attention to maintenance of parts in proper position.

—The multiplicity of dressings which have been suggested for fractures of the clavicle attest the fact that so long as primary indications are observed the treatment can be made very simple. These indications are to keep the shoulder upward, outward, and backward, as it tends to drop in the opposite way. The action of three muscles is of great importance in considering the proper treatment of these cases, i. e., the sternomastoid and the trapezius, because they tend to pull fragments upward, and the pectoralis major because advantage can be taken of its arrangement to overcome upward displacement. It was Moore, of Rochester, who taught many years in Buffalo, who showed how this could be done. The fibers of the great pectoral which arise highest, i. e., from the clavicle, are those which are inserted lowest along the bicipital groove of the humerus, because of the semi-revolution made by the tendon of this muscle as it passes to its insertion. By putting the arm in such a position that these fibers are pulled upon the operator may counteract the upward pull of the other muscles just mentioned. This is the underlying feature of Moore’s suggestion; to force the elbow far backward, into a position which is for the time being uncomfortable, in order thus to pull down fragments which jut up beneath the skin. Any dressing which permits this position to be maintained will be equally serviceable. Moore suggests for this purpose what he calls a double figure-of-eight, which is shown in Figs. 284 and 285. It is put on as follows: A strip of cloth, sheeting, or anything of the kind, about two yards in length and folded sufficiently to make a strong strip eight inches wide, is held near its middle over the surgeon’s hand. This hand is placed beneath the elbow of the injured side, so that the strip crosses the under surface of the flexed forearm at the elbow. One end, which should be the longer, lying to the inner side, is passed upward and in front of the arm, carried over the shoulder across the back and under the opposite axilla, then over in front of the sound shoulder, meeting on the back the other end, which is carried up first over the outside of the forearm, then behind the shoulder and across the spine. This

bandage should be pulled tightly, while an assistant holds the elbow as far backward and upward as the patient can tolerate it, as the more the position is exaggerated the more are the clavicular fibers of the muscle pulled upon and the better are the fragments held in place. This dressing not only meets the three primary indications laid down, but gives the added advantage just described. By it the shoulders are drawn backward and fixed to each other. The elbow should be lifted as the dressing is applied, so as to lift the shoulder. Most of the cloth materials used for such a dressing are more or less elastic, and it may need to be tightened once or twice a day during the time that it is worn. After a few days, when consolidation should have occurred, it may be changed for some other less irksome form of dressing. The hand should be supported in a sling. This dressing is useful in dislocations of the clavicle, especially of its outer end, and in every kind of injury in which the indication is to hold the shoulder upward and backward. In simple cases without much displacement the primary indications may be more simply met by a dressing of adhesive plaster, known in the East as Sayre’s and in the West as Freer’s. It consists of two strips of plaster of about the width of the arm itself. One of them is wound around the upper end of the arm, close to the shoulder, in such a way that, as it is passed around the back and brought over the chest, the arm and shoulder are pulled backward. The other strip passes from beneath the elbow of the injured side obliquely up and over the opposite shoulder. When it is applied the elbow should be firmly lifted. After the completion of either of these dressings the injured shoulder should appear at least one inch higher than the well one. Should the patient’s arm and chest be hairy they should be shaved before the application of the plaster strips. Like other material, plaster will stretch and slip, and these, like other dressings, should be readjusted every day or two, for the shoulder should be kept elevated for at least a week.

F. 284

apparatus (back view)

F. 285

apparatus (front view)

When the case is complicated by other injuries necessitating confinement in bed it is sufficient to keep the patient flat upon the back and without a pillow. In this position the shoulder falls naturally in the direction desired, and perhaps no other attention will be required. Many other methods are combined with a figure-of-eight bandage, crossing the back and forming a loop over each shoulder, so as to keep it from dropping forward.

While the results of treatment are nearly always good, if one is insistent upon a minimum of deformity, confinement upon the back on a hard bed is the surest way to obtain satisfactory results. Cases in which there is little or no tendency to deformity need only the simplest support by which rest may be ensured.

Epiphyseal separations are to be treated as fractures.

Moore’s
Moore’s

FRACTURES OF THE SCAPULA.

The most frequent fracture of the scapula is that of the acromion; this is usually the result of direct violence, such as a fall upon the tip of the shoulder. Detachment of this fragment permits a peculiar flattening of the shoulder, but without dislocation. The fragment can be easily felt, while the deltoid is displaced and its rounded contour lost. Treatment consists solely in forcing the arm upward, by dressings applied beneath the elbow, thus lifting the fragment into its place; fibrous union occurring here much more often than osseous, the latter is possible only in case a good apposition be maintained. Any form of dressing, then, by which the elbow is crowded upward and rest maintained will be appropriate.

The surgical neck is occasionally detached, sometimes with and sometimes without the coracoid process. As the humerus is attached to it by the capsular ligament the arm drops with the fragment when the patient is in the upright position, and the elbow will be found lower than that of the injured side. The arm is unduly mobile, and the fragment can usually be seized and crepitus obtained within the axilla. Here it is necessary to hold the arm up, as it controls the position of the fragment. It is usually sufficient to lift the elbow up and bind the arm firmly to the side, the scapula being immobilized by broad straps of adhesive plaster.

The coracoid process is occasionally detached, usually by muscular violence, i. e., it is pulled off by the coracobrachialis and the coracoid head of the biceps which arise from it. The injury is recognized by failure to detect the process in its proper place, and usually by discovery of the fragment at a point below its normal position, to which it has been drawn out by the muscles arising from it. Ligamentous union can be secured by relaxing these muscles, which is done by placing the hand over the opposite shoulder and dressing the arm firmly against the chest. I have seen paralysis of the arm result from excessive callus after fracture of the coracoid.

The spine, body, and the angles of the scapula are occasionally broken by severe violence. In the aged comminution may occur. Crepitus can be nearly always obtained. It may be necessary to distinguish the scapular fracture from one of the ribs beneath it. The

treatment consists in simply fixing the shoulder-blade upon the chest, to which it is naturally adapted, by firm bandages, which shall immobilize not only it but the arm as well.

FRACTURES OF THE HUMERUS.

At the upper end of the humerus we deal with fracture of the processes, i. e., the tuberosities, which may be torn off by violent action of the muscles therein inserted; of the anatomical neck, which is rare and occurs most often in the aged; of the surgical neck, which is the most common; or, in the young, epiphyseal separation, which is the equivalent of the last named. Separation of the tuberosities is diagnosticated mainly by exclusion, possibly by x-rays. The anatomical neck lies within the capsule, and should the head be thus detached it might remain as a foreign body in the joint, having no means of securing nutrition. Fractures of the head of the bone are not classical and are usually the result of gunshot injuries or extreme violence. In all of these injuries there will be swelling, loss of function, while crepitus is sometimes obtained, but is very difficult to locate, even under an anesthetic. The diagnosis is to be made mostly by exclusion.

The surgical neck is the most frequently broken; the line of fracture passing below the tuberosities and above the muscles inserted along the bicipital groove. Therefore the pectoralis and the latissimus muscles will both conspire to pull the upper end of the shaft toward the thorax to such an extent that it can be felt in the axilla. This gives its axis a different direction, while all the muscles extending from the shoulder to the forearm will tend to produce shortening. Deformity is usually distinct, crepitus is easily obtained, and undue mobility is well marked. The head of the bone can be detected in its proper place beneath the deltoid, but does not rotate with the shaft. In rare instances a certain amount of impaction may make this evidence of fracture obscure. Epiphyseal separation will give the same signs and symptoms.

Treatment.

—The primary indication here is to overcome muscle pull by traction in a direction toward the crest of the pelvis of the same side. At the same time, with a certain degree of

coaxing of the upper end of the shaft outward and a little forward, it may be possible to so re-apply broken surfaces to each other, and so affix the arm to the thorax, as to be effective. When serious difficulty, however, is encountered the writer advises traction, applied to the arm alone, if the patient be able to be upright, or to the arm and forearm, if he be confined in bed. It will take considerable stretching to overcome the combined action of all the muscles which tend to produce displacement. Along with such treatment a coaptation splint should be applied, the best being that which can be carefully molded to the parts and adapted to their needs. For this purpose a molded plaster-of-Paris splint is preferable to one of metal made to some standard size. In the dressing it is necessary to include not only the shoulder and arm but also the forearm, otherwise the principle of physiological rest would not be enforced. Fig. 286 illustrates the common tendency to displacement in these injuries.

Fracture of the surgical neck is occasionally combined with dislocation of the head of the humerus, by which such an injury is seriously complicated. Reduction may be attempted by manipulation. Until recently it was generally advised to wait for a week or ten days, and until consolidation had occurred, and then to make the attempt at reduction; but Porter and McBurney have shown that it is advisable to cut down upon the dislocated upper fragment, and, fixing it with forceps or with an instrument shaped like a corkscrew or hook, to force it back into place again. If this be done under the strictest precautions it lends no serious features to the case, while, in most respects, such a procedure would greatly simplify it, the wound being closed with or without drainage, and the usual fracture dressing being applied.

In cases of old fracture and dislocation the head of the bone should be exsected, the functional result thus obtained being excellent.

Epiphyseal separation has been too often mistaken for dislocation. Fig. 287, from Moore, shows how the periosteum is not necessarily entirely detached, but is stripped up to form a hinge, the fragment displaced forward, and its outer aspect often turned upward. This makes traction in an outward direction an essential feature of the

replacement of the fractured surfaces, the manipulation being combined with fixation of the fragment so far as it can be seized through the axilla. If the epiphysis is properly slipped over upon the end of the humerus the case assumes ordinary features, and is to be dressed as usual.

F. 286

Fracture of the surgical neck of humerus. (Hoffa.)

F. 287

Separation of the upper epiphysis of the humerus; displacement forward of the lower fragment. (Moore.)

The shaft of the bone is frequently broken, lines of fracture running in all directions and occurring at all levels. A variety of displacement may take place. The evidences of fracture are usually recognizable and diagnosis is not difficult. The brachial artery and the musculospiral nerve are occasionally involved, either in callus or by primary injury from a spicule of bone. These fractures are more liable

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.