ࡱ> []ZM 4bjbj== -LWWh0Vl8888888L8<L16Lp=?L(H1J1J1J1J1J1J1$2 5n189=n1E88g1EEE88H1EH1E2Ew J,u880@ p?Ld v0B0101J0B5)50ELL8888Macros: Automating tasks you perform frequently If you perform a task repeatedly in MS Project, you can automate it with a macro. A Macro is a small program that consists of a recorded series of keystrokes or mouse clicks to help automate a repetitive task. The macro is stored in a Visual Basic module and can be run whenever you need to perform the task. You record a macro just as you record music with a tape recorder. Then run the macro to repeat, or "play back," the commands. Before you record or create a macro, plan the steps and commands you want the macro to perform. If you make a mistake when you record the macro, corrections you make will also be recorded. Each time you record a macro, the macro is stored in a module attached to your project. With Visual Basic for Applications (VBA), you can create more complete macros. You can also edit macros, copy macros from one module to another, copy macros between different projects, rename the modules that store the macros, or rename the macros. Benefits of Macros Automate time-consuming, everyday tasks Enhance MS Project to suit the skill level of your users Simply creating and distributing project information Recording a Macro Decide first what it is you want to automate Write down the steps of your macro Choose View, Zoom Select Entire Project Press the OK Button Record the macro How to Record a Macro On the Tools menu, point to Macro, and then click Record New Macro In the Macro name box, enter a name for the macro Note: The first character of the macro name must be a letter. Other characters can be letters, numbers, or an underscore. Spaces are not allowed so use an underscore character as a word separator. To run the macro by keyboard shortcut, enter a letter in the Shortcut key box. Use CTRL+ letter for lowercase or CTRL+SHIFT+ letter for uppercase, but not a number or special character In the Store macro in box, choose to store the macro in the active project file or Global file. To make the macro available to the other projects that use the Global file, click Global File Type a description of the macro, its purpose or other information, in the Description box Row References Relative: Begins the macro relative to the row that is selected when you run the macro. For example, you can record a macro that puts information into three adjacent rows in the Task Name field of the Gantt Chart view. If you select Relative, the information is placed into three rows, beginning with the selected row, when you run the macro. Absolute (ID): Always begins the macro at the same row that you specified when you recorded the macro. For example, if you record a macro that puts information into rows 1, 2, and 3 of the Task Name field of the Gantt Chart view, then the information is always put into rows 1, 2, and 3 when you run the macro, regardless of which row is selected when you run the macro. Column References Absolute (Field): Always operates the macro on the same fields that you specified when you recorded the macro. For example, you can record a macro that puts information into the Name, Start, and Duration fields. If this option is selected, the information is always put into the Name, Start, and Duration fields when you run the macro. This occurs even if the fields are arranged differently than when you recorded the macro, and even if these fields are not currently viewable in the Gantt Chart. Relative: Runs the macro relative to the column position specified when you recorded the macro. For example, if you record a macro that puts information into the second, third, and fourth columns on the Gantt Chart, then the information is always put into the second, third, and fourth columns when you run the macro, regardless of which column is selected and of the fields displayed in the columns. Project will continue to record macros with these settings until you change them or quit Project. Click OK and then carry out the actions you want to record On the Tools menu, point to Macro, and then click Stop Recorder Run a macro in Microsoft Project On the Tools menu, point to Macro, and then click Macros Select the macro you want to run from the Macro name list Click Run Note: To interrupt a macro before it finishes, press CTRL+BREAK. Viewing a macro from the Visual Basic Editor The Visual Basis Editor allows you to look at in words the steps captured using the Macro Recorder. On the Tools menu, point to Macro, and then click Macros Select the macro you want to run from the Macro name list Click Edit Assigning a Macro to a Toolbar Button You can run a macro from a button on a built-in toolbar or a custom toolbar. On the Tools menu, point to Customize, and then click Toolbars If the toolbar that contains the button is not visible, click the Toolbars tab, and then select the check box next to the toolbar name If the button you want to run the macro from is not on a toolbar, click the Commands tab, and then click All Macros in the Categories list. In the Commands list, drag the macro name onto the toolbar If you want to assign a macro to a button already on a toolbar, click the Commands tab, select the button, click Modify Selection, and then click Assign Macro Macros Available within Microsoft Project 2000 Adjust_Dates if you want to change the project start date run this macro to have all constraint dates in the schedule updated with the same difference as well Analyze_Timescaled_Data to create Earned Value graphs in Excel. This macro is also on the Analysis toolbar Format_Durations Allows you to change the time unit in the Duration field from Days to Minutes, Hours or Weeks Install_PERT_Analysis Calculate_PERT PERT_Analysis Set_PERT_Weights Toggle_PERT_Toolbar ResMgnt_TaskEntry changes the view Gantt Chart and Task Form in a detail format for resource loading Rollup_Formatting will display the names of the tasks marked to be rolled up on the summary task alternatively above and below the task bar Toggle_Read_Only will toggle the files between Read_Only and Read_Write mode Update_File updates a read-only file to the most recently saved version Web Sites to Obtain Macros  HYPERLINK http://www.mpug.com www.mpug.com  HYPERLINK http://www.mvps.org/project/ www.mvps.org/project/  HYPERLINK http://www.scramsoftware.vallnet.com/downloads.htm www.scramsoftware.vallnet.com/downloads.htm  HYPERLINK http://www.office.microsoft.com/downloads www.office.microsoft.com/downloads Web Sites with Information on Visual Basic  HYPERLINK http://www.msdn.microsoft.com/scripting www.msdn.microsoft.com/scripting  HYPERLINK http://www.msdn.microsoft/vba www.msdn.microsoft/vba Macros Available on the MPUG Web Site Date Range Filter Filters out activities within a certain date range. Allows you to specify the range you wish. This will open a window which allows you to input the number of days before and the number of days after time "now" and then filters the information based on what you input. Notify Macro Uses Outlook to notify team members of project tasks that have reached a threshold so that resources assigned to successors can be notified prior to their tasks start. Outlook Application Macro Customizes Outlook application. Allows Microsoft Project team members to email and discuss their project with posts to a common folder. HTML Converter Allows Microsoft Project users to communicate project data across the Internet. Easily converts data tables into web pages. Search and Replace Macro Gives Microsoft users access to advanced Search and Replace functionality. VISUAL BASIC Code Basics This section presents information on code writing mechanics, including breaking and combining lines of code, adding comments to your code, using numbers in code, and following naming conventions in Visual Basic. Breaking a Single Statement into Multiple Lines You can break a long statement into multiple lines in the Code window using the line-continuation character (a space followed by an underscore). Using this character can make your code easier to read, both online and when printed. The following code is broken into three lines with line-continuation characters ( _): Data1.RecordSource = _ "SELECT * FROM Titles, Publishers" _ & "WHERE Publishers.PubId = Titles.PubID" _ & "AND Publishers.State = 'CA'" Combining Statements on One Line There is usually one Visual Basic statement to a line. However, you can place two or more statements on a line if you use a colon (:) to separate them: Text1.Text = "Hello" : Red = 255 : Text1.BackColor = Red In order to make the code more readable, however, it's better to place each statement on a separate line. Adding Comments to Your Code This symbol ( ' ) tells Visual Basic to ignore the words that follow it. Such words are remarks placed in the code for the benefit of the developer, and other programmers who might examine the code later. For example: ' This is a comment beginning at the left edge of the screen. Text1.Text = "Hi!" ' Place friendly greeting in text box. Comments can follow a statement on the same line or can occupy an entire line. Naming Conventions in Visual Basic While writing Visual Basic code, you declare and name many elements (Sub and Function procedures, variables, constants, and so on). The names of the procedures, variables, and constants that you declare in your Visual Basic code must follow these guidelines: They must begin with a letter They can't contain embedded periods or type-declaration characters (special characters that specify a data type They can be no longer than 255 characters. The names of controls, forms, classes, and modules must not exceed 40 characters They can't be the same as restricted keywords Auto_Open A macro named Auto_Open will execute automatically when the project file is first opened. Auto_Close A macro named Auto_Close will execute automatically when the project file is closed. A restricted keyword is a word that Visual Basic uses as part of its language. This includes predefined statements (If and Loop), functions (Len and Abs), and operators (Or and Mod). Code Commenting Conventions All procedures should begin with a brief comment describing what they do. This description should not describe the implementation details (how it does it) because these often change over time, resulting in unnecessary comment maintenance work, or worse, erroneous comments. The code itself and any necessary inline comments describe the implementation. Arguments passed to a procedure should be described when their purpose is not obvious and when the procedure expects the arguments to be in a specific range. Return values for functions and variables that are changed by a procedure, especially through reference arguments, should also be described at the beginning of each procedure. Procedure header comments should include the following section headings. For examples, see the "Formatting Your Code" section that follows. PRIVATESection HeadingComment ContentsPurposeWhat the procedure does (not how).AssumptionsList of any external variable, control, or other element whose state affects this procedure.EffectsList of the procedure's effect on each external variable, control, or other element.InputsExplanation of each argument that is not obvious. Each argument should be on a separate line with inline comments.Return ValuesExplanation of the value returned. Remember the following points: Every important variable declaration should include an inline comment describing the use of the variable being declared Variables, controls, and procedures should be named clearly to ensure that inline comments are only needed for complex implementation details At the beginning of your script, you should include an overview that describes the script, enumerating objects, procedures, algorithms, dialog boxes, and other system dependencies. Sometimes a piece of pseudocode describing the algorithm can be helpful Formatting Your Code Screen space should be conserved as much as possible, while still allowing code formatting to reflect logic structure and nesting. Here are a few suggestions: Indent standard nested blocks four spaces Indent the overview comments of a procedure one space Indent the highest level statements that follow the overview comments four spaces, with each nested block indented an additional four spaces MPUG Greater Cincinnati Chapter  PAGE 1 Macros Chas Eddingfield, Vice President 1% & 9 ; K b   \ j   ] l &(Eu#$&'OPQfghi  01]^ OJQJhjOJQJUhjUjUjU0JjU jU 6OJQJ 5OJQJOJQJG01.g & ; L b U & F hx@&x@& & Fx@& & F h^ & F & Fx  & F !h44U  m | FXJ=xLV(a & F x@&x & Fx@& & Fx & F x@& & F hx@& & F hx@& & Fx@& & Fd@&aYFu '8LA & F  & F ! & F h!88^8  & F ! & Fx@&x@& & F x@&&h2]@ +!!!!!""##$*$V$v$ v%" & F & F &$ & F & F !!!""#v$$/%i%j%%%&J'''((O)P)))))**z++......022h44444ſ0J j0JU5jU jU0JOJQJ 5OJQJB*OJQJhphjOJQJUh OJQJh0JjOJQJUhjOJQJUh:v$$/%0%i%j%%%&& 'I'J'''(((P)))`***z++, ! & F & F v%,F....../*/+/7///////m0n0|00x$If<$$If0$ $$ la $$Ifa$000091122z3{333h4i444444 &d P  & F<$$If0$ $$ la444444OJQJ0J j0JU0JmHnHu+0P/ =!"#$%DyK  www.mpug.comyK *http://www.mpug.com/DyK www.mvps.org/project/yK :http://www.mvps.org/project/3DyK ,www.scramsoftware.vallnet.com/downloads.htmyK fhttp://www.scramsoftware.vallnet.com/downloads.htmDyK #www.office.microsoft.com/downloadsyK Thttp://www.office.microsoft.com/downloadsDyK !www.msdn.microsoft.com/scriptingyK Phttp://www.msdn.microsoft.com/scriptingDyK www.msdn.microsoft/vbayK <http://www.msdn.microsoft/vbaD^$ #h$ $ ill$j$ $ kll%dl$ $ mll&n$ $ oll'p$ $ qll(rr$ $ sll# i0@0 Normal_HmH sH tH @@ Heading 1$dd@& 5OJQJF@F Heading 2$<@&56CJOJQJ@@@ Heading 3$<@& CJOJQJHH Heading 4$$@&a$5OJQJhtH u<A@< Default Paragraph Font<< H1$dd@&5CJ0KH$htH u(U@( Hyperlink>*B*<< TOC 1$xx(da$ 56CJ66 TOC 2$xx(da$6:: TOC 3$xx(d^a$:: TOC 4$xx(d^a$:: TOC 5$Xxx(d^Xa$:: TOC 6$ xx(d^ a$:: TOC 7$xx(d^a$:: TOC 8$xx(d^a$:: TOC 9$xxx(d^xa$,@, Header  !, @, Footer  !:)@: Page Number6CJOJQJkH8V@8 FollowedHyperlink>*B* 88 H2$dd@&5CJ$htH u$O$ CODE CJOJQJdOd Preformatted( # ~= z9!v%OJQJhtH u$X@$ Emphasis6HB@"H Body Text " &$B*OJQJhtH u0L01.g&;LbUm| F X J =xLV(aYFu '8LA&h2]@+ * V v /!0!i!j!!!"" #I#J###$$$P%%%`&&&z''(F*****+*+7+++++m,|,,,,9--..z/{///h0i00000                       ==   LL        F F F F F F F F F F F F     2 2   "  (    (! ! !!!("" " " ""($$ $ $ $ $  $((((((((((((( ( ( (// / /@0@0@@ UUUX44!%U av$,04 "#$4#&Pfh 0]0XXXXXX!(*X!t?b$ IYN`$t`2$"Ưm62$fsrYoaZ}@0(  B S  ?0 _Toc522513825 _Toc522513826 _Toc522513827 _Toc522513829 _Toc522513830 _Toc522513831 _Toc522513833 _Hlt522513609 _Toc522513834u*0/a+0$fg01256;]3 C F R ] m %&&&`&j&{&&g0h00000K P C H gmC!F!!""#H#h00033333333h0i000Chas EddingfieldsC:\Documents and Settings\cedding\My Documents\MS Project\MPUG\Sept 6, 2001\My Presentation\Macros Presentation.docChas EddingfieldsC:\Documents and Settings\cedding\My Documents\MS Project\MPUG\Sept 6, 2001\My Presentation\Macros Presentation.docChas EddingfieldNC:\DOCUME~1\cedding\LOCALS~1\Temp\AutoRecovery save of Macros Presentation.asdChas EddingfieldNC:\DOCUME~1\cedding\LOCALS~1\Temp\AutoRecovery save of Macros Presentation.asdChas EddingfieldNC:\DOCUME~1\cedding\LOCALS~1\Temp\AutoRecovery save of Macros Presentation.asdChas EddingfieldNC:\DOCUME~1\cedding\LOCALS~1\Temp\AutoRecovery save of Macros Presentation.asdChas EddingfieldNC:\DOCUME~1\cedding\LOCALS~1\Temp\AutoRecovery save of Macros Presentation.asdChas EddingfieldsC:\Documents and Settings\cedding\My Documents\MS Project\MPUG\Sept 6, 2001\My Presentation\Macros Presentation.docChas EddingfieldNC:\DOCUME~1\cedding\LOCALS~1\Temp\AutoRecovery save of Macros Presentation.asd Kirk.Vantine9C:\Documents and Settings\kirk.vantine\Desktop\Macros.doc.>PGPBi  m0 Pcj Z Y K|P) CN) 0 !]u2P32 ^4 Q6 )z= Ux> iGI N }N {U !]u2G \ Yg D!m0 !N)z=}Nm;lQ6K| u@CJ8OJQJo(" P! @CJ0OJQJo( !@h ^`OJQJo(*****+*+++7+++++++m,n,|,,,h000@/Tt{//0P@UnknownGz Times New Roman5Symbol3& z Arial?5 z Courier New?&Maiandra GD"0h{Y&{Y&'U!20d1F2/Macros: Automating tasks you perform frequentlyChas Eddingfield Kirk.VantineOh+'0$ <H d p |0Macros: Automating tasks you perform frequentlyacrChas Eddingfieldg thashas Normal.dotf Kirk.Vantineeld2rkMicrosoft Word 9.0t@F#@j?@j?'I]http://www.mpug.com/46500.00000000003Chas Eddingfield, Cincinnati Financial Corporati ?@ABCDEFGHIKLMNOPQuTUWXYa\S_`RbcdefghijklmnopqrstwvxRoot Entry F@`u^ Data '1Table/5WordDocument-LSummaryInformation(JDocumentSummaryInformation8CompObjjObjectPool e? e? ( !#$%'.)*+,-/123  FMicrosoft Word Document MSWordDocWord.Document.89q՜.+,D՜.+,\ hp|  cfcU1 0Macros: Automating tasks you perform frequently Titlep,H     $0< _PID_HLINKSOrderAuthor/Presenter Description0Chapter Date AddedSubject Keywords _Author _Category Categories Approval Level _Comments Assigned ToA$AOhttp://www.msdn.microsoft/vba!| (http://www.msdn.microsoft.com/scriptingP *http://www.office.microsoft.com/downloads:>3http://www.scramsoftware.vallnet.com/downloads.htmShttp://www.mvps.org/project/="Project_x0020_Version"> This value indicates the number of saves or revisions. The application is responsible for updating this value after each revision. ns:ds="http://schemas.openxmlformats.org/officeDocument/2006/customXml"/>repoint/v3/contenttype/forms">DocumentLibraryFDocumentLibraryFormDocumentLibraryFormDocumentLibraryFormAA9-0840-4FEF-98C5-8116D8536CE9}" xml as.microsoft.com/office/2006/metadata/longProperties"/>