How To Make Pricing Calculator In Excel For Mac Vba Editor

Re: Formula for tiered pricing Hi, I need help with a similar formula for my Excel sheet. We are working with a manufacturer who offers product based on the quantity that we order. You can access the VBA environment in Excel 2016 by opening the Microsoft Visual Basic for Applications window. First, be sure that the Developer tab is visible in the toolbar in Excel. The Developer tab is the toolbar that has the buttons to open the VBA editor and create Form/ActiveX Controls like buttons, checkboxes, etc.

Recently, we shared an overview of the new extensibility capabilities available for developers as part of the new Office 2016. In addition to the improvements discussed there, including connecting the applications you build to the data and services available in Office 365 and creating add-ins that connect to third-party services, we continue to support developers working in VBA by adding new objects and members to the VBA object model across nearly all the Office applications.

One thing to note, our engineering focus is Office web add-ins – web add-ins work across devices and platforms, and developers enjoy a modern web development experience. Support for web add-ins is already available in Office 2013 and 2016 for Windows, Office for iPad, and Outlook for Mac today, and they’ll come to the rest of Office clients over time.

Office 2016 for Windows

New VBA object model features

Several Office desktop applications have new features that are exposed in the VBA object model. Here are some of the highlights:

  • Excel has a new set of data import and shaping features that are based on Power Query technology and that let users query information in files, databases, Azure sites, and from other sources, and to combine queries. To support this feature, Excel exposes the new Queries and WorkbookQuery objects, and their associated properties and methods. For more information about Power Query, see this blog post and download this sample. Excel exposes several new methods on the WorksheetFunction object to enable forecasting of statistical functions. Finally, there are a number of new objects related to the existing Model object, such as the ModelFormatBoolean and ModelFormatCurrency objects, and many new properties on each of these new objects.
  • Outlook has added a new PreviewPane object and a new WordEditor property on that object, which allow access to the body of the message currently loaded in the preview pane. This property is intended to let Windows-Eyes and other screen readers to have access to the body of a message in the preview pane.
  • Project adds new Engagement and EngagementComment objects and associated methods and properties to allow programmatic access to engagements scheduled in a project.
  • Visio has added new OM to permit information rights management (IRM) of Visio documents.

Office 2016 for Mac

Since the launch of Office 2016 for Mac in July, Mac OS X users around the world have been able to take advantage of the highly anticipated new features and improvements since the 2011 release. At the same time, some of our users also have sent us feedback requesting further improvements to our VBA support, particularly around VBA add-ins.

How To Make Pricing Calculator In Excel For Mac Vba Editor

In response to this feedback, we’ll further improve Office 2016 for Mac’s support for VBA add-ins. Specifically, we’ll be adding Office ribbon customization via Ribbon XML, and making other improvements to Word, Excel, and PowerPoint for Mac to match their Windows desktop versions.

Ribbon customization via Ribbon XML

We are excited to announce that with the latest Office for Mac update, you’ll be able to fully customize the ribbon across Word, Excel, and PowerPoint for the Mac using familiar Ribbon XML.

Here’s how the Mac Word ribbon looks with a custom tab.

If you’ve been customizing the ribbon on Office for Windows, you’ll find the Mac experience to be very similar. However, there are certain important differences to know about, as described in the table below.

Comparison of ribbon customization functionality in Office 2016 for Mac and Windows


* Most familiar Office Fluent Control Identifiers are compatible with Office for Mac. Some may not be available.
** May support this in future.
*** Office 2016 for Mac doesn’t support third-party COM-Add-ins. No current plans to support these in the future. Ribbon customization via Ribbon XML is now available, however, it remains in preview and is disabled by default for this update. Follow the steps below to enable or disable it across Word, Excel and PowerPoint using the Terminal on Mac.

To enable Ribbon XML:

  1. Open Terminal.
  2. Type this command:
    “defaults write com.microsoft.office EnableRibbonXmlDeveloperMode -bool YES”
  3. Reboot the app.

To disable Ribbon XML:

How To Make Pricing Calculator In Excel For Mac Vba Editor Excel

  1. Open Terminal.
  2. Type this command:
    “defaults write com.microsoft.office EnableRibbonXmlDeveloperMode -bool NO”
  3. Reboot the app.

In early 2016, ribbon customization via Ribbon XML will be enabled by default for all customers.

How To Make Pricing Calculator In Excel For Mac Vba Editor Download

FAQ

How do I edit Ribbon XML?

You can edit Ribbon XML by using familiar Custom UI Editor Tool, which remains available only on Windows.

Will these updates be pushed as part of the auto-update process?

Yes. These updates will be pushed to all customers using Microsoft Auto Updater.

Is the structure of the XML file the same as that for Office for Windows?

Yes, Office 2016 for Mac ribbon reads customizations from CustomUI.xml and CustomUI14.xml.

Will the Office 2016 for Mac ribbon load the XML from both files, CustomUI.xml and CustomUI14.xml?

Yes, and just like the behavior in Office for Windows, CustomUI14.xml will be given preference over CustomUI.xml.

Will the Office 2016 for Mac ribbon accept PNG files that are loaded into the document’s custom UI as control images?

Yes.

Visual Basic Editor

You spoke, we heard!

As we continue to improve the overall Visual Basic story on Office 2016 for Mac, we’ve added the following features to Visual Basic Editor:

  • Ability to add modules from within the Project Viewer
  • Ability to add library references using a dialog
  • Ability to use shortcut keys for debugging within Visual Basic Editor, such as Command+Shift+I for Step Into, Command+Shift+O for Step Over.

New Commands

You might not be aware that we recently added two new commands to the Visual Basic object model for Mac: GrantAccessToMultipleFiles and AppleScriptTask.

We also added a new conditional, “MAC_OFFICE_VERSION”. (See New Commands Documentation later in this article.)

As Office 2016 for Mac is sandboxed, users are prompted to grant access every time a file access request is made. GrantAccessToMultipleFiles is a command that takes an array of file pointers and helps minimize the number of these prompts.

Sandboxing also severely breaks the previously existing MacScript command that allows the use of inline AppleScript in Visual Basic. This is where AppleScriptTask can help. Users can store an AppleScript file at a specified location on the disk and use AppleScriptTask within VB to invoke it. The location of these scripts is specified by the operating system and cannot be altered.

The MAC_OFFICE_VERSION conditional lets macros determine what version of Mac Office the user is running. This comes handy in cases where certain commands (like the two above) are available only on a given version, and invoking them on another version may result in errors.

Since Office 2016 for Mac Beta, we’ve been keeping close watch on issues relating to these new commands and have been making fixes. With this update, we’re releasing some important fixes that will considerably improve the overall performance of these commands. In particular, we’ve fixed various timeout issues related to AppleScriptTask.

New Commands Documentation

AppleScriptTask

The AppleScriptTask command executes an AppleScript script. This is similar to the MacScript command except that it runs an AppleScript file located outside the sandboxed app.

For example:

on myapplescripthandler(paramString)#do something with paramString return 'You told me ' & paramString end myapplescripthandler

GrantAccessToMultipleFiles

Unlike VB macros in Office for Mac 2011, VB macros in Office 2016 for Mac don’t have access to external files by default. The Office 2016 for Mac apps are sandboxed and so they lack the required permissions to access external files.

Existing macro file commands are changed to prompt the user for file access if the app doesn’t already have access to it. This means that macros that access external files cannot run unattended; they’ll need user interaction to approve file access the first time each file is referenced. You can use the GrantAccessToMultipleFiles command to minimize the number of prompts and make the experience better (see below).

GrantAccessToMultipleFiles

This command lets you input an array of file paths and prompt the user for permission to access them.

Sub VersionConditionals()#If MAC_OFFICE_VERSION >= 15 Then Debug.Print 'We are running on Mac 15+' #Else Debug.Print 'We are not running on Mac 15+' #End If #If Mac Then Debug.Print 'We are running on a Mac' #Else Debug.Print 'We are not running on a Mac' #End If End Sub

Note The “#If Mac” conditional remains unchanged from Office for Mac 2011.

Plan Ahead

Starting in Office 2016 for Mac, custom menus that were supported in Office for Mac 2011 are not supported anymore. We’re officially deprecating support for custom menus and CommandBar controls. A few legacy CommandBar controls may continue to appear on the Add-ins tab, however, we advise that you don’t write new code that uses either of the two. Starting today, if you have a VB add-in that requires a UI, it’s best to use Ribbon XML to write that UI.

Overview of UI Extensibility points and corresponding support in Office 2016 for Mac

Overall, as we’ve mentioned before, we recommend that customers develop macros or VB add-ins in Office for Windows and use Office for Mac to debug, if needed. We’ll continue to ensure compatibility of existing macros and make improvements to the IDE.

Documentation & GitHub

Our developer help for VBA has also undergone some changes. The first thing to highlight is that we’ve moved our content to an “evergreen” model. That means that starting with Office 2013, our help topics are no longer specific to a single version of Office, but instead are combined topics that span all the versions of Office to which they apply. You can still view topics from Office 2010 by clicking Other Versions right below the topic title.

In addition to the evergreen model, we’ve published the VBA documentation on GitHub. By doing so, it allows a much faster process to improve our documentation and a way for you in the community to engage and contribute to the content. At the top of each VBA topic in MSDN, you’ll see a contributors notice like this:

Calculator

Simply click the suggest and submit changes link in the Contribute to this content section and you’ll be taken to the same article on GitHub where you can propose changes. After you submit your changes, our team is notified immediately and will respond to your change request. You’ll receive notifications about your change request and status; our team may also notify you if we need more information about your change request.

How To Make Pricing Calculator In Excel For Mac Vba Editor Views

For more details on how to submit changes, bugs, or issues, or to contribute to the content itself through GitHub, see this article.

Although VBA offers a decent assortment of built-in functions, you might not always find exactly what you need. Fortunately, you can also use most of Excel’s worksheet functions in your VBA procedures. The only worksheet functions that you cannot use are those that have an equivalent VBA function. For example, you can’t use Excel’s RAND function (which generates a random number) because VBA has an equivalent function: Rnd.

VBA makes Excel’s worksheet functions available through the WorksheetFunction object, which is contained in the Application object. Here’s an example of how you can use Excel’s SUM function in a VBA statement:

You can omit either the Application part or the WorksheetFunction part of the expression. In either case, VBA figures out what you’re doing. In other words, these three expressions all work exactly the same:

My personal preference is to use the WorksheetFunction part just to make it perfectly clear that the code is using an Excel function.

Worksheet function examples

How To Make Pricing Calculator In Excel For Mac Vba Editor

Here, you discover how to use worksheet functions in your VBA expressions.

Finding the maximum value in a range

Here’s an example that shows how to use Excel’s MAX worksheet function in a VBA procedure. This procedure displays the maximum value in column A of the active worksheet:

You can use the MIN function to get the smallest value in a range. And as you might expect, you can use other worksheet functions in a similar manner. For example, you can use the LARGE function to determine the kth-largest value in a range. The following expression demonstrates this:

Notice that the LARGE function uses two arguments. The second argument represents the kth part — 2, in this case (the second-largest value).

Calculating a mortgage payment

The next example uses the PMT worksheet function to calculate a mortgage payment. Three variables are used to store the data that’s passed to the Pmt function as arguments. A message box displays the calculated payment.

As the following statement shows, you can also insert the values directly as the function arguments:

However, using variables to store the parameters makes the code easier to read and modify, if necessary.

Using a lookup function

The following example uses VBA’s InputBox and MsgBox functions, plus Excel’s VLOOKUP function. It prompts for a part number and then gets the price from a lookup table. Below, range A1:B13 is named PriceList.

The range, named PriceList, contains prices for parts.

Here’s how the GetPrice procedure works:

  • VBA’s InputBox function asks the user for a part number.

  • The part number the user enters is assigned to the PartNum variable.

  • The next statement activates the Prices worksheet, just in case it’s not already the active sheet.

  • The code uses the VLOOKUP function to find the part number in the table.

  • Notice that the arguments you use in this statement are the same as those you would use with the function in a worksheet formula. This statement assigns the result of the function to the Price variable.

  • The code displays the price for the part via the MsgBox function.

This procedure doesn’t have any error handling, and it fails miserably if you enter a nonexistent part number. (Try it.) If this were an actual application that’s used in an actual business, you would want to add some statements that deal with errors more gracefully.

Entering worksheet functions

You can’t use the Excel Paste Function dialog box to insert a worksheet function into a VBA module. Instead, enter such functions the old-fashioned way: by hand. However, you can use the Paste Function dialog box to identify the function you want to use and find out about its arguments.

You can also take advantage of the VBE’s Auto List Members option, which displays a drop-down list of all worksheet functions. Just type Application.WorksheetFunction, followed by a period. Then you see a list of the functions you can use. If this feature isn’t working, choose the VBE’s Tools → Options command, click the Editor tab, and place a check next to Auto List Members.

Getting a list of worksheet functions that you can use in your VBA code.

More about using worksheet functions

Newcomers to VBA often confuse VBA’s built-in functions and Excel’s workbook functions. A good rule to remember is that VBA doesn’t try to reinvent the wheel. For the most part, VBA doesn’t duplicate Excel worksheet functions.

For most worksheet functions that are unavailable as methods of the WorksheetFunction object, you can use an equivalent VBA built-in operator or function. For example, the MOD worksheet function is not available in the WorksheetFunction object because VBA has an equivalent: its built-in Mod operator.

Bottom line? If you need to use a function, first determine whether VBA has something that meets your needs. If not, check out the worksheet functions. If all else fails, you may be able to write a custom function by using VBA.