{
	"id": "5ba8f27c-7eac-4246-aa57-1631f1606bad",
	"created_at": "2026-04-06T02:11:30.242881Z",
	"updated_at": "2026-04-10T03:19:57.458549Z",
	"deleted_at": null,
	"sha1_hash": "a1abbba266ce446eb26fcece8fcbd67ff54e600f",
	"title": "Getting started with VBA in Office",
	"llm_title": "",
	"authors": "",
	"file_creation_date": "0001-01-01T00:00:00Z",
	"file_modification_date": "0001-01-01T00:00:00Z",
	"file_size": 96151,
	"plain_text": "Getting started with VBA in Office\r\nBy o365devx\r\nArchived: 2026-04-06 02:09:10 UTC\r\nAre you facing a repetitive clean up of fifty tables in Word? Do you want a particular document to prompt the user\r\nfor input when it opens? Are you having difficulty figuring out how to get your contacts from Microsoft Outlook\r\ninto a Microsoft Excel spreadsheet efficiently?\r\nYou can perform these tasks and accomplish a great deal more by using Visual Basic for Applications (VBA) for\r\nOffice—a simple, but powerful programming language that you can use to extend Office applications.\r\nThis article is for experienced Office users who want to learn about VBA and who want some insight into how\r\nprogramming can help them to customize Office.\r\nThe Office suite of applications has a rich set of features. There are many different ways to author, format, and\r\nmanipulate documents, email, databases, forms, spreadsheets, and presentations. The great power of VBA\r\nprogramming in Office is that nearly every operation that you can perform with a mouse, keyboard, or a dialog\r\nbox can also be done by using VBA. Further, if it can be done once with VBA, it can be done just as easily a\r\nhundred times. (In fact, the automation of repetitive tasks is one of the most common uses of VBA in Office.)\r\nBeyond the power of scripting VBA to accelerate every-day tasks, you can use VBA to add new functionality to\r\nOffice applications or to prompt and interact with the user of your documents in ways that are specific to your\r\nbusiness needs. For example, you could write some VBA code that displays a pop up message that reminds users\r\nto save a document to a particular network drive the first time they try to save it.\r\nThis article explores some of the primary reasons to leverage the power of VBA programming. It explores the\r\nVBA language and the out-of-the-box tools that you can use to work with your solutions. Finally, it includes some\r\ntips and ways to avoid some common programming frustrations and missteps.\r\nNote\r\nInterested in developing solutions that extend the Office experience across multiple platforms? Check out the new\r\nOffice Add-ins model. Office Add-ins have a small footprint compared to VSTO Add-ins and solutions, and you\r\ncan build them by using almost any web programming technology, such as HTML5, JavaScript, CSS3, and XML.\r\nThere are several principal reasons to consider VBA programming in Office.\r\nVBA is effective and efficient when it comes to repetitive solutions to formatting or correction problems. For\r\nexample, have you ever changed the style of the paragraph at the top of each page in Word? Have you ever had to\r\nreformat multiple tables that were pasted from Excel into a Word document or an Outlook email? Have you ever\r\nhad to make the same change in multiple Outlook contacts?\r\nhttps://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/getting-started-with-vba-in-office\r\nPage 1 of 12\n\nIf you have a change that you have to make more than ten or twenty times, it may be worth automating it with\r\nVBA. If it is a change that you have to do hundreds of times, it certainly is worth considering. Almost any\r\nformatting or editing change that you can do by hand, can be done in VBA.\r\nThere are times when you want to encourage or compel users to interact with the Office application or document\r\nin a particular way that is not part of the standard application. For example, you might want to prompt users to\r\ntake some particular action when they open, save, or print a document.\r\nDo you need to copy all of your contacts from Outlook to Word and then format them in some particular way? Or,\r\ndo you need to move data from Excel to a set of PowerPoint slides? Sometimes simple copy and paste does not do\r\nwhat you want it to do, or it is too slow. Use VBA programming to interact with the details of two or more Office\r\napplications at the same time and then modify the content in one application based on the content in another.\r\nVBA programming is a powerful solution, but it is not always the optimal approach. Sometimes it makes sense to\r\nuse other ways to achieve your aims.\r\nThe critical question to ask is whether there is an easier way. Before you begin a VBA project, consider the built-in tools and standard functionalities. For example, if you have a time-consuming editing or layout task, consider\r\nusing styles or accelerator keys to solve the problem. Can you perform the task once and then use CTRL+Y\r\n(Redo) to repeat it? Can you create a new document with the correct format or template, and then copy the content\r\ninto that new document?\r\nOffice applications are powerful; the solution that you need may already be there. Take some time to learn more\r\nabout Office before you jump into programming.\r\nBefore you begin a VBA project, ensure that you have the time to work with VBA. Programming requires focus\r\nand can be unpredictable. Especially as a beginner, never turn to programming unless you have time to work\r\ncarefully. Trying to write a \"quick script\" to solve a problem when a deadline looms can result in a very stressful\r\nsituation. If you are in a rush, you might want to use conventional methods, even if they are monotonous and\r\nrepetitive.\r\nYou might think that writing code is mysterious or difficult, but the basic principles use every-day reasoning and\r\nare quite accessible. Microsoft Office applications are created in such a way that they expose things called objects\r\nthat can receive instructions, in much the same way that a phone is designed with buttons that you use to interact\r\nwith the phone. When you press a button, the phone recognizes the instruction and includes the corresponding\r\nnumber in the sequence that you are dialing. In programming, you interact with the application by sending\r\ninstructions to various objects in the application. These objects are expansive, but they have their limits. They can\r\nonly do what they are designed to do, and they will only do what you instruct them to do.\r\nFor example, consider the user who opens a document in Word, makes a few changes, saves the document, and\r\nthen closes it. In the world of VBA programming, Word exposes a Document object. By using VBA code, you can\r\ninstruct the Document object to do things such as Open, Save, or Close.\r\nThe following section discusses how objects are organized and described.\r\nhttps://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/getting-started-with-vba-in-office\r\nPage 2 of 12\n\nDevelopers organize programming objects in a hierarchy, and that hierarchy is called the object model of the\r\napplication. Word, for example, has a top-level Application object that contains a Document object. The\r\nDocument object contains Paragraph objects and so on. Object models roughly mirror what you see in the user\r\ninterface. They are a conceptual map of the application and its capabilities.\r\nThe definition of an object is called a class, so you might see these two terms used interchangeably. Technically, a\r\nclass is the description or template that is used to create, or instantiate, an object.\r\nOnce an object exists, you can manipulate it by setting its properties and calling its methods. If you think of the\r\nobject as a noun, the properties are the adjectives that describe the noun and the methods are the verbs that\r\nanimate the noun. Changing a property changes some quality of appearance or behavior of the object. Calling one\r\nof the object methods causes the object to perform some action.\r\nThe VBA code in this article runs against an open Office application where many of the objects that the code\r\nmanipulates are already up and running; for example, the Application itself, the Worksheet in Excel, the Document\r\nin Word, the Presentation in PowerPoint, the Explorer and Folder objects in Outlook. Once you know the basic\r\nlayout of the object model and some key properties of the Application that give access to its current state, you can\r\nstart to extend and manipulate that Office application with VBA in Office.\r\nIn Word, for example, you can change the properties and invoke the methods of the current Word document by\r\nusing the ActiveDocument property of the Application object. This ActiveDocument property returns a\r\nreference to the Document object that is currently active in the Word application. \"Returns a reference to\" means\r\n\"gives you access to.\"\r\nThe following code does exactly what it says; that is, it saves the active document in the application.\r\nApplication.ActiveDocument.Save\r\nRead the code from left to right, \"In this Application, with the Document referenced by ActiveDocument, invoke\r\nthe Save method.\" Be aware that Save is the simplest form of method; it does not require any detailed instructions\r\nfrom you. You instruct a Document object to Save and it does not require any more input from you.\r\nIf a method requires more information, those details are called parameters. The following code runs the SaveAs\r\nmethod, which requires a new name for the file.\r\nApplication.ActiveDocument.SaveAs (\"New Document Name.docx\")\r\nValues listed in parentheses after a method name are the parameters. Here, the new name for the file is a parameter\r\nfor the SaveAs method.\r\nYou use the same syntax to set a property that you use to read a property. The following code executes a method to\r\nselect cell A1 in Excel and then to set a property to put something in that cell.\r\nhttps://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/getting-started-with-vba-in-office\r\nPage 3 of 12\n\nApplication.ActiveSheet.Range(\"A1\").Select\r\n Application.Selection.Value = \"Hello World\"\r\nThe first challenge in VBA programming is to get a feeling for the object model of each Office application and to\r\nread the object, method, and property syntax. The object models are similar in all Office applications, but each is\r\nspecific to the kind of documents and objects that it manipulates.\r\nIn the first line of the code snippet, there is the Application object, Excel this time, and then the ActiveSheet,\r\nwhich provides access to the active worksheet. After that is a term not as familiar, Range, which means \"define a\r\nrange of cells in this way.\" The code instructs Range to create itself with just A1 as its defined set of cells. In other\r\nwords, the first line of code defines an object, the Range, and runs a method against it to select it. The result is\r\nautomatically stored in another property of the Application called Selection.\r\nThe second line of code sets the Value property of Selection to the text \"Hello World\", and that value appears in\r\ncell A1.\r\nThe simplest VBA code that you write might simply gain access to objects in the Office application that you are\r\nworking with and set properties. For example, you could get access to the rows in a table in Word and change their\r\nformatting in your VBA script.\r\nThat sounds simple, but it can be incredibly useful; once you can write that code, you can harness all of the power\r\nof programming to make those same changes in several tables or documents, or make them according to some\r\nlogic or condition. For a computer, making 1000 changes is no different from making 10, so there is an economy\r\nof scale here with larger documents and problems, and that is where VBA can really shine and save you time.\r\nNow that you know something about how Office applications expose their object models, you are probably eager\r\nto try calling object methods, setting object properties, and responding to object events. To do so, you must write\r\nyour code in a place and in a way that Office can understand; typically, by using the Visual Basic Editor. Although\r\nit is installed by default, many users don't know that it is even available until it is enabled on the ribbon.\r\nAll Office applications use the ribbon. One tab on the ribbon is the Developer tab, where you access the Visual\r\nBasic Editor and other developer tools. Because Office does not display the Developer tab by default, you must\r\nenable it by using the following procedure:\r\n1. On the File tab, choose Options to open the Options dialog box.\r\n2. Choose Customize Ribbon on the left side of the dialog box.\r\n3. Under Choose commands from on the left side of the dialog box, select Popular Commands.\r\n4. Under Customize the Ribbon on the right side of the dialog box, select Main Tabs in the drop down list\r\nbox, and then select the Developer checkbox.\r\n5. Choose OK.\r\nNote\r\nhttps://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/getting-started-with-vba-in-office\r\nPage 4 of 12\n\nIn Office 2007, you displayed the Developer tab by choosing the Office button, choosing Options, and then\r\nselecting the Show Developer tab in Ribbon check box in the Popular category of the Options dialog box.\r\nAfter you enable the Developer tab, it is easy to find the Visual Basic and Macros buttons.\r\nFigure 1. Buttons on the Developer tab\r\nButtons on the Developer tab\r\nTo protect Office users against viruses and dangerous macro code, you cannot save macro code in a standard\r\nOffice document that uses a standard file extension. Instead, you must save the code in a file with a special\r\nextension. For example you cannot save macros in a standard Word document with a .docx extension; instead, you\r\nmust use a special Word Macro-Enabled Document with a .docm extension.\r\nWhen you open a .docm file, Office security might still prevent the macros in the document from running, with or\r\nwithout telling you. Examine the settings and options in the Trust Center on all Office applications. The default\r\nsetting disables macro from running, but warns you that macros have been disabled and gives you the option to\r\nturn them back on for that document.\r\nYou can designate specific folders where macros can run by creating Trusted Locations, Trusted Documents, or\r\nTrusted Publishers. The most portable option is to use Trusted Publishers, which works with digitally signed\r\ndocuments that you distribute. For more information about the security settings in a particular Office application,\r\nopen the Options dialog box, choose Trust Center, and then choose Trust Center Settings.\r\nNote\r\nSome Office applications, like Outlook, save macros by default in a master template on your local computer.\r\nAlthough that strategy reduces the local security issues on your own computer when you run your own macros, it\r\nrequires a deployment strategy if you want to distribute your macro.\r\nWhen you choose the Macro button on the Developer tab, it opens the Macros dialog box, which gives you\r\naccess to VBA subroutines or macros that you can access from a particular document or application. The Visual\r\nBasic button opens the Visual Basic Editor, where you create and edit VBA code.\r\nAnother button on the Developer tab in Word and Excel is the Record Macro button, which automatically\r\ngenerates VBA code that can reproduce the actions that you perform in the application. Record Macro is a terrific\r\ntool that you can use to learn more about VBA. Reading the generated code can give you insight into VBA and\r\nprovide a stable bridge between your knowledge of Office as a user and your knowledge as a programmer. The\r\nonly caveat is that the generated code can be confusing because the Macro editor must make some assumptions\r\nabout your intentions, and those assumptions are not necessarily accurate.\r\n1. Open Excel to a new Workbook and choose the Developer tab in the ribbon. Choose Record Macro and\r\naccept all of the default settings in the Record Macro dialog box, including Macro1 as the name of the\r\nmacro and This Workbook as the location.\r\n2. Choose OK to begin recording the macro. Note how the button text changes to Stop Recording. Choose\r\nthat button the instant you complete the actions that you want to record.\r\nhttps://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/getting-started-with-vba-in-office\r\nPage 5 of 12\n\n3. Choose cell B1 and type the programmer's classic first string: Hello World. Stop typing and look at the\r\nStop Recording button; it is grayed out because Excel is waiting for you to finish typing the value in the\r\ncell.\r\n4. Choose cell B2 to complete the action in cell B1, and then choose Stop Recording.\r\n5. Choose Macros on the Developer tab, select Macro1 if it is not selected, and then choose Edit to view the\r\ncode from Macro1 in the Visual Basic Editor.\r\nFigure 2. Macro code in Visual Basic Editor\r\nMacro code in Visual Basic Editor\r\nThe macro that you created should look similar to the following code.\r\nSub Macro1()\r\n'\r\n' Macro1 Macro\r\n'\r\n'\r\n Range(\"B1\").Select\r\n ActiveCell.FormulaR1C1 = \"Hello World\"\r\n Range(\"B2\").Select\r\nEnd Sub\r\nBe aware of the similarities to the earlier code snippet that selected text in cell A1, and the differences. In this\r\ncode, cell B1 is selected, and then the string \"Hello World\" is applied to the cell that has been made active. The\r\nquotes around the text specify a string value as opposed to a numeric value.\r\nRemember how you chose cell B2 to display the Stop Recording button again? That action shows up as a line of\r\ncode as well. The macro recorder records every keystroke.\r\nThe lines of code that start with an apostrophe and colored green by the editor are comments that explain the code\r\nor remind you and other programmers the purpose of the code. VBA ignores any line, or portion of a line, that\r\nbegins with a single quote. Writing clear and appropriate comments in your code is an important topic, but that\r\ndiscussion is out of the scope of this article. Subsequent references to this code in the article don't include those\r\nfour comment lines.\r\nWhen the macro recorder generates the code, it uses a complex algorithm to determine the methods and the\r\nproperties that you intended. If you don't recognize a given property, there are many resources available to help\r\nyou. For example, in the macro that you recorded, the macro recorder generated code that refers to the\r\nFormulaR1C1 property. Not sure what that means?\r\nNote\r\nBe aware that Application object is implied in all VBA macros. The code that you recorded works with\r\nApplication. at the beginning of each line.\r\nhttps://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/getting-started-with-vba-in-office\r\nPage 6 of 12\n\nSelect FormulaR1C1 in the recorded macro and press F1. The Help system runs a quick search, determines that\r\nthe appropriate subjects are in the Excel Developer section of the Excel Help, and lists the FormulaR1C1\r\nproperty. You can choose the link to read more about the property, but before you do, be aware of the Excel\r\nObject Model Reference link near the bottom of the window. Choose the link to view a long list of objects that\r\nExcel uses in its object model to describe the Worksheets and their components.\r\nChoose any one of those to see the properties and methods that apply to that particular object, along with cross\r\nreferences to different related options. Many Help entries also have brief code examples that can help you. For\r\nexample, you can follow the links in the Borders object to see how to set a border in VBA.\r\nWorksheets(1).Range(\"A1\").Borders.LineStyle = xlDouble\r\nThe Borders code looks different from the recorded macro. One thing that can be confusing with an object model\r\nis that there is more than one way to address any given object, cell A1 in this example.\r\nSometimes the best way to learn programming is to make minor changes to some working code and see what\r\nhappens as a result. Try it now. Open Macro1 in the Visual Basic Editor and change the code to the following.\r\nSub Macro1()\r\n Worksheets(1).Range(\"A1\").Value = \"Wow!\"\r\n Worksheets(1).Range(\"A1\").Borders.LineStyle = xlDouble\r\nEnd Sub\r\nTip\r\nUse Copy and Paste as much as possible when working with code to avoid typing errors.\r\nYou don't need to save the code to try it out, so return to the Excel document, choose Macros on the Developer\r\ntab, choose Macro1, and then choose Run. Cell A1 now contains the text Wow! and has a double-line border\r\naround it.\r\nFigure 3. Results of your first macro\r\nResults of your first macro\r\nYou just combined macro recording, reading the object model documentation, and simple programming to make a\r\nVBA program that does something. Congratulations!\r\nDid not work? Read on for debugging suggestions in VBA.\r\nThe VBA community is very large; a search on the Web can almost always yield an example of VBA code that\r\ndoes something similar to what you want to do. If you cannot find a good example, try to break the task down into\r\nsmaller units and search on each of those, or try to think of a more common, but similar problem. Starting with an\r\nexample can save you hours of time.\r\nhttps://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/getting-started-with-vba-in-office\r\nPage 7 of 12\n\nThat does not mean that free and well-thought-out code is on the Web waiting for you to come along. In fact, some\r\nof the code that you find might have bugs or mistakes. The idea is that the examples you find online or in VBA\r\ndocumentation give you a head start. Remember that learning programming requires time and thought. Before you\r\nget in a big rush to use another solution to solve your problem, ask yourself whether VBA is the right choice for\r\nthis problem.\r\nProgramming can get complex quickly. It's critical, especially as a beginner, that you break the problem down to\r\nthe smallest possible logical units, then write and test each piece in isolation. If you have too much code in front\r\nof you and you get confused or muddled, stop and set the problem aside. When you come back to the problem,\r\ncopy out a small piece of the problem into a new module, solve that piece, get the code working, and test it to\r\nensure that it works. Then move on to the next part.\r\nThere are two main types of programming errors: syntax errors, which violate the grammatical rules of the\r\nprogramming language, and run-time errors, which look syntactically correct, but fail when VBA attempts to\r\nexecute the code.\r\nAlthough they can be frustrating to fix, syntax errors are easy to catch; the Visual Basic Editor beeps and flashes\r\nat you if you type a syntax error in your code.\r\nFor example, string values must be surrounded by double quotes in VBA. To find out what happens when you use\r\nsingle quotes instead, return to the Visual Basic Editor and replace the \"Wow!\" string in the code example with\r\n'Wow!' (that is, the word Wow enclosed in single quotes). If you choose the next line, the Visual Basic Editor\r\nreacts. The error \"Compile error: Expected: expression\" is not that helpful, but the line that generates the error\r\nturns red to tell you that you have a syntax error in that line and as a result, this program will not run.\r\nChoose OK and change the text back to\"Wow!\".\r\nRuntime errors are harder to catch because the programming syntax looks correct, but the code fails when VBA\r\ntries to execute it.\r\nFor example, open the Visual Basic Editor and change the Value property name to ValueX in your Macro,\r\ndeliberately introducing a runtime error since the Range object does not have a property called ValueX. Go back\r\nto the Excel document, open the Macros dialog box and run Macro1 again. You should see a Visual Basic\r\nmessage box that explains the run-time error with the text, \"Object doesn't support this property of method.\"\r\nAlthough that text is clear, choose Debug to find out more.\r\nWhen you return to the Visual Basic Editor, it is in a special debug mode that uses a yellow highlight to show you\r\nthe line of code that failed. As expected, the line that includes the ValueX property is highlighted.\r\nYou can make changes to VBA code that is running, so change ValueX back to Value and choose the little green\r\nplay button underneath the Debug menu. The program should run normally again.\r\nIt's a good idea to learn how to use the debugger more deliberately for longer, more complex programs. At a\r\nminimum, learn a how to set break-points to stop execution at a point where you want to take a look at the code,\r\nhow to add watches to see the values of different variables and properties as the code runs, and how to step\r\nhttps://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/getting-started-with-vba-in-office\r\nPage 8 of 12\n\nthrough the code line by line. These options are all available in the Debug menu and serious debugger users\r\ntypically memorize the accompanying keyboard shortcuts.\r\nTo open the Developer Reference that is built into Office Help, open the Help reference from any Office\r\napplication by choosing the question mark in the ribbon or by pressing F1. Then, to the right of the Search button,\r\nchoose the dropdown arrow to filter the contents. Choose Developer Reference. If you don't see the table of\r\ncontents in the left panel, choose the little book icon to open it, and then expand the Object Model Reference from\r\nthere.\r\nFigure 4. Filtering on developer Help applies to all Office applications\r\nFiltering on developer Help applies to all Office applications\r\nTime spent browsing the Object Model reference pays off. After you understand the basics of VBA syntax and the\r\nobject model for the Office application that you are working with, you advance from guesswork to methodical\r\nprogramming.\r\nOf course the Microsoft Office Developer Center is an excellent portal for articles, tips, and community\r\ninformation.\r\nAll programmers get stuck sometimes, even after reading every reference article they can find and losing sleep at\r\nnight thinking about different ways to solve a problem. Fortunately, the Internet has fostered a community of\r\ndevelopers who help each other solve programming problems.\r\nAny search on the Web for \"office developer forum\" reveals several discussion groups. You can search on \"office\r\ndevelopment\" or a description of your problem to discover forums, blog posts, and articles as well.\r\nIf you have done everything that you can to solve a problem, don't be afraid to post your question to a developers\r\nforum. These forums welcome posts from newer programmers and many of the experienced developers are glad to\r\nhelp.\r\nThe following are a few points of etiquette to follow when you post to a developer forum:\r\nBefore you post, look on the site for an FAQ or for guidelines that members want you to follow. Ensure\r\nthat you post content that is consistent with those guidelines and in the correct section of the forum.\r\nInclude a clear and complete code sample, and consider editing your code to clarify it for others if it is part\r\nof a longer section of code.\r\nDescribe your problem clearly and concisely, and summarize any steps that you have taken to solve the\r\nproblem. Take the time to write your post as well as you can, especially if you are flustered or in a hurry.\r\nPresent the situation in a way that will make sense to readers the first time that they read the problem\r\nstatement.\r\nBe polite and express your appreciation.\r\nhttps://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/getting-started-with-vba-in-office\r\nPage 9 of 12\n\nAlthough this article is short and only scratches the surface of VBA and programming, it is hopefully enough to\r\nget you started.\r\nThis section briefly discusses a few more key topics.\r\nIn the simple examples in this article you manipulated objects that the application had already created. You might\r\nwant to create your own objects to store values or references to other objects for temporary use in your\r\napplication. These are called variables.\r\nTo use a variable in VBA, must tell VBA which type of object the variable represents by using the Dim statement.\r\nYou then set its value and use it to set other variables or properties.\r\n Dim MyStringVariable As String\r\n MyStringVariable = \"Wow!\"\r\n Worksheets(1).Range(\"A1\").Value = MyStringVariable\r\nThe simple programs in this article execute one line at a time, from the top down. The real power in programming\r\ncomes from the options that you have to determine which lines of code to execute, based on one or more\r\nconditions that you specify. You can extend those capabilities even further when you can repeat an operation many\r\ntimes. For example, the following code extends Macro1.\r\nSub Macro1()\r\n If Worksheets(1).Range(\"A1\").Value = \"Yes!\" Then\r\n Dim i As Integer\r\n For i = 2 To 10\r\n Worksheets(1).Range(\"A\" \u0026 i).Value = \"OK! \" \u0026 i\r\n Next i\r\n Else\r\n MsgBox \"Put Yes! in cell A1\"\r\n End If\r\nEnd Sub\r\nType or paste the code into the Visual Basic Editor and then run it. Follow the directions in the message box that\r\nappears and change the text in cell A1 from Wow! to Yes! and run it again to see the power of looping. This code\r\nsnippet demonstrates variables, branching and looping. Read it carefully after you see it in action and try to\r\ndetermine what happens as each line executes.\r\nHere are a few scripts to try; each solves a real-world Office problem.\r\nSub MakeMessage()\r\n Dim OutlookMessage As Outlook.MailItem\r\n Set OutlookMessage = Application.CreateItem(olMailItem)\r\n OutlookMessage.Subject = \"Hello World!\"\r\n OutlookMessage.Display\r\nhttps://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/getting-started-with-vba-in-office\r\nPage 10 of 12\n\nSet OutlookMessage = Nothing\r\nEnd Sub\r\nBe aware that there are situations in which you might want to automate email in Outlook; you can use templates\r\nas well.\r\nSub DeleteEmptyRows()\r\n SelectedRange = Selection.Rows.Count\r\n ActiveCell.Offset(0, 0).Select\r\n For i = 1 To SelectedRange\r\n If ActiveCell.Value = \"\" Then\r\n Selection.EntireRow.Delete\r\n Else\r\n ActiveCell.Offset(1, 0).Select\r\n End If\r\n Next i\r\nEnd Sub\r\nBe aware that you can select a column of cells and run this macro to delete all rows in the selected column that\r\nhave a blank cell.\r\nSub RemoveEmptyTextBoxes()\r\n Dim SlideObj As Slide\r\n Dim ShapeObj As Shape\r\n Dim ShapeIndex As Integer\r\n For Each SlideObj In ActivePresentation.Slides\r\n For ShapeIndex = SlideObj.Shapes.Count To 1 Step -1\r\n Set ShapeObj = SlideObj.Shapes(ShapeIndex)\r\n If ShapeObj.Type = msoTextBox Then\r\n If Trim(ShapeObj.TextFrame.TextRange.Text) = \"\" Then\r\n ShapeObj.Delete\r\n End If\r\n End If\r\n Next ShapeIndex\r\n Next SlideObj\r\nEnd Sub\r\nBe aware that this code loops through all of the slides and deletes all text boxes that don't have any text. The count\r\nvariable decrements instead of increments because each time the code deletes an object, it removes that object\r\nfrom the collection, which reduces the count.\r\nSub CopyCurrentContact()\r\n Dim OutlookObj As Object\r\n Dim InspectorObj As Object\r\nhttps://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/getting-started-with-vba-in-office\r\nPage 11 of 12\n\nDim ItemObj As Object\r\n Set OutlookObj = CreateObject(\"Outlook.Application\")\r\n Set InspectorObj = OutlookObj.ActiveInspector\r\n Set ItemObj = InspectorObj.CurrentItem\r\n Application.ActiveDocument.Range.InsertAfter (ItemObj.FullName \u0026 \" from \" \u0026 ItemObj.CompanyName)\r\nEnd Sub\r\nBe aware that this code copies the currently open contact in Outlook into the open Word document. This code only\r\nworks if there is a contact currently open for inspection in Outlook.\r\nHave questions or feedback about Office VBA or this documentation? Please see Office VBA support and\r\nfeedback for guidance about the ways you can receive support and provide feedback.\r\nSource: https://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/getting-started-with-vba-in-office\r\nhttps://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/getting-started-with-vba-in-office\r\nPage 12 of 12",
	"extraction_quality": 1,
	"language": "EN",
	"sources": [
		"MITRE"
	],
	"references": [
		"https://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/getting-started-with-vba-in-office"
	],
	"report_names": [
		"getting-started-with-vba-in-office"
	],
	"threat_actors": [],
	"ts_created_at": 1775441490,
	"ts_updated_at": 1775791197,
	"ts_creation_date": 0,
	"ts_modification_date": 0,
	"files": {
		"pdf": "https://archive.orkl.eu/a1abbba266ce446eb26fcece8fcbd67ff54e600f.pdf",
		"text": "https://archive.orkl.eu/a1abbba266ce446eb26fcece8fcbd67ff54e600f.txt",
		"img": "https://archive.orkl.eu/a1abbba266ce446eb26fcece8fcbd67ff54e600f.jpg"
	}
}