Altova MapForce Server 2025 Advanced Edition

Microsoft Visual Basic for Applications (VBA) is primarily used for automating tasks in Microsoft Office. However, it is also possible to call the MapForce Server API from VBA and execute mappings. The following instructions have been tested on MapForce Server and the VBA for Microsoft Office 2013. Instructions may differ if you are using another VBA development environment.

 

Prerequisites

Before you can call the MapForce Server API functions from your VBA project, note the following prerequisites:

 

1.Microsoft Office and MapForce Server must be installed on the same machine.

2.The architecture of MapForce Server (32-bit or 64-bit) must match that of Microsoft Office. For example, if you run VBA on Microsoft Office 32-bit, make sure that you use MapForce Server 32-bit. To find out whether your Office product runs on 64-bit, click the File tab, click Account, and then click "About Excel" (or "About Word").

3.The MapForce Server library must be referenced from your VBA project (see instructions below).

 

How to add a reference to the MapForce Server Library from your VBA project

1.In a macro-enabled Microsoft Office document (.docm, .xlsm), on the Developer tab, click Visual Basic.

By default, the Developer tab is not enabled in Microsoft Office. To enable the Developer tab in an Office 2013 program, right-click the ribbon and select Customize the Ribbon from the context menu. Then, in the Options dialog box, select the Developer check box under "Main Tabs".

2.In the VBA development environment, in the Tools menu, click References.

mfs_vba_ref

3.Click to select the MapForce Server Type Library.

 

How to call the MapForce Server API

Once you have added a reference to the MapForce Server Library in your VBA project, you can enter the VBA code in the Code Editor window. For example, the following sample code calls MapForce Server and runs a mapping executable file (mapping.mfx) that takes an input parameter called "outfile" having the value "output.csv".

 

Sub RunMapping()
  ' Create a new instance of the MapForce Server
  Dim objMFS As New MapForceServerLib.Server
  With objMFS
      ' Set the working directory
      ' (used as base if the mapping has relative paths)
       .WorkingDirectory = "C:\temp\"
      ' If the mapping has parameters, supply them
      Call .AddParameter("outfile", "output.csv")
      ' Run the mapping
       .Run ("C:\temp\mapping.mfx")
  End With
End Sub

 

Press F5 to debug the VBA code and run the mapping.

mfs_vba_code

© 2018-2024 Altova GmbH