'
' Retrieve data for all sheets
'
Public Sub Retrieve()
Dim Sheet As Worksheet
On Error GoTo ERR_HANDLER
For Each Sheet In ActiveWorkbook.Worksheets
FP_RetrieveSilently Sheet
Next
Exit Sub
ERR_HANDLER:
MsgBox "Error occurred on sheet " & Sheet.Name & ": " & vbCrLf & vbCrLf & Err.Description, vbOKOnly + vbExclamation
End Sub
'
' Reflect data for all sheets
'
Public Sub Reflect()
Dim Sheet As Worksheet
On Error GoTo ERR_HANDLER
For Each Sheet In ActiveWorkbook.Worksheets
FP_ReflectSilently Sheet
Next
Exit Sub
ERR_HANDLER:
MsgBox "Error occurred on sheet " & Sheet.Name & ": " & vbCrLf & vbCrLf & Err.Description, vbOKOnly + vbExclamation
End Sub
Using Excel-Link Functions in Macros
This manual is in pilot operation.
|
VBA procedures are provided to use [Excel-Link] functions in macros.
1. Preparation
(Ensure that Excel-Link is registered as an add-in beforehand.)
To use [Excel-Link] functions in macros, you must configure "Reference Settings" so that the macro-containing workbook can access the [Excel-Link] add-in file.
Open the Visual Basic Editor via the Microsoft Excel menu, then select
. In the displayed dialog box, check the box to the left of "FP_EXCEL_LINK" in the "Available References" list.2. Explanation of VBA Procedures
(1) Procedures to Call fusions Menu Functions from Macros
Each item in the fusions menu has a corresponding VBA procedure (Sub). These procedures do not take any arguments. By using these procedures, you can, for example, assign functions to buttons on a sheet, allowing users to execute functions by clicking them.
Procedure | Description | Corresponding fusions Menu Item |
---|---|---|
FP_Retrieve |
Executes data retrieval for the currently selected sheet. |
"Retrieve" |
FP_Reflect |
Executes data reflection for the currently selected sheet. |
"Reflect" |
FP_Clear |
Executes sheet clear processing for the currently selected sheet. |
"Clear" |
FP_RetrieveReflect |
Executes data retrieval and reflection for the currently selected sheet. |
"Retrieve then Reflect" |
FP_BatchRetrieve |
Executes data retrieval for all sheets in the currently selected workbook with names starting with "FP_", processing them sequentially from left to right. |
"Batch" > "Retrieve" |
FP_BatchReflect |
Executes data reflection for all sheets in the currently selected workbook with names starting with "FP_", processing them sequentially from left to right. |
"Batch" > "Reflect" |
FP_BatchClear |
Executes sheet clear processing for all sheets in the currently selected workbook with names starting with "FP_", processing them sequentially from left to right. |
"Batch" > "Clear" |
FP_BatchRetrieveReflect |
Executes data retrieval and reflection for all sheets in the currently selected workbook with names starting with "FP_", processing them sequentially from left to right. |
"Batch" > "Retrieve then Reflect" |
FP_PivotQuery |
Executes a pivot query. |
"PivotQuery" |
FP_ChangeLocales |
Displays a dialog box to switch the display language. |
"Language" |
FP_ConfigureConnection |
Displays a dialog box to configure the connection settings. |
"Connection" |
FP_ConfigureRegions |
Displays a dialog box to configure linked regions. |
"Regions" |
FP_CreateSpecifications |
Outputs the linked region settings as a specification document. |
"Specifications" |
FP_PasteMember |
Displays a member selection screen and pastes the selected member labels into the target cell/range. |
"Paste Members" |
FP_ConfigureSheetAttributes |
Displays a dialog box to configure processing conditions applied to the entire sheet (not just linked regions). |
"Sheet Attributes" |
FP_ProtectSheet |
Protects the sheet using the registered Excel-Link Sheet Password. |
"Protect Sheet" |
FP_ChangePassword |
Displays a dialog box to register/change the Excel-Link Sheet Password. |
"Sheet Password" |
FP_ToggleLicenseReminder |
Toggles the display of the license reminder. |
"License Reminder Disabled" |
FP_About |
Displays the "About" dialog box. |
"About" |
(2) Procedures to Retrieve and Modify Excel-Link Settings
These procedures allow retrieving and modifying settings within [Excel-Link].
Procedure | Description | Arguments | Return Value |
---|---|---|---|
FP_GetLocale |
Retrieves the currently selected display language. |
(None) |
Japanese: "ja" |
FP_SetLocale |
Sets the display language. |
Locale As String Japanese: "ja" |
(None) |
FP_SetPassword |
Sets the Excel-Link Sheet Password. Ensure the sheet is unprotected before execution. After execution, the sheet will be protected. |
Sheet As Worksheet Password As String |
(None) |
FP_IsLicenseReminderDisabled |
Retrieves the display status of the license reminder. |
(None) |
Displayed: False |
FP_SetLicenseReminderDisabled |
Sets the display status of the license reminder. |
IsLicenseReminderDisabled As Boolean |
(None) |
FP_CopyConfigurations |
Copies all Excel-Link configuration settings from one sheet to another. |
SourceSheet As Worksheet DestinationSheet As Worksheet |
(None) |
3. Procedures for Complex Processing
When executing Retrieve/Reflect Data from fusions menu, only the currently selected sheet is processed. However, if you want to process multiple sheets based on various conditions, you can use the following procedures to create macros that selectively process target sheets based on specific conditions.
If you simply want to process multiple sheets at once, you can use the Batch Processing function from the fusions menu instead of writing a macro. |
Procedure | Description | Arguments | Return Value |
---|---|---|---|
FP_RetrieveSilently |
Executes data retrieval for the specified sheet. |
Sheet As Worksheet |
True if target linked regions exist, False otherwise. |
FP_ReflectSilently |
Executes data reflection for the specified sheet. |
(Same as above) |
(Same as above) |
FP_RetrieveReflectSilently |
Executes data retrieval and reflection for the specified sheet. |
(Same as above) |
(Same as above) |
FP_ClearSilently |
Executes sheet clear processing for the specified sheet. |
(Same as above) |
(Same as above) |
FP_AdvancedPasteMember |
Displays a member selection screen and pastes selected member labels into the specified range. |
TargetRange As Range Optional Arguments: ApplicationLabel As String DimensionLabel As String IsDimensionSelectable As Boolean NamePastingMode As Integer 0: Do not paste. |
(None) |
FP_GetParticipantsForCurrentUser |
Returns a list of participant units assigned to the current user in the specified application. |
ApplicationLabel As String Application label |
Collection Contains elements of the FP_Descriptor class, which has the following properties: Label Each stores the label and name of the participant unit. |
FP_ShowMenu |
Toggles menu visibility. |
Show As Boolean |
(None) |
FP_ShowRibbon |
Toggles ribbon visibility. |
Show As Boolean |
(None) |
(fusion_place >= 14.1) FP_CallWebApi |
Calls the Web-API. |
WebApiRequest As WebApiRequest WebApiRequest has the following properties: WebApiType As String Description As String Parameters As Collection Contents As Collection |
WebApiResponse WebApiResponse has the following properties: WebApiType As String Description As String WebApiCode As FP_WebApiCode WebApiCodeString As String Message As String StartedAt As String EndedAt As String ReturnedContents As Collection ResponseXml As String |
(fusion_place >= 14.1) FP_CreateWebApiRequest |
Generates a WebApiRequest object. |
WebApiType As String Description As String |
WebApiRequest |
3. Code Samples
(1) Silent Procedures
Among the procedures listed above, those with "Silently" at the end of their names (hereafter referred to as silent procedures) differ from FP_Retrieve, FP_Reflect, FP_RetrieveReflect, and FP_Clear (hereafter referred to as interactive procedures) in the following ways:
-
The target sheet is specified as an argument.
Interactive procedures always process the currently selected sheet. -
They return a value (Function procedure).
Interactive procedures do not return a value (Sub procedure). -
They do not display a message box upon completion.
Interactive procedures display a message box upon completion, but silent procedures do not. This prevents interruptions when processing multiple sheets, as displaying a message box after each sheet would disrupt the workflow. -
If there is an error in the sheet configuration, they raise an error instead of displaying a message box.
Interactive procedures display a message box if there is an error in the sheet configuration, but silent procedures raise an error instead.
Calling macros can handle errors using the On Error statement, allowing for flexible handling such as skipping errors and continuing with the next sheet.
When an error occurs, its details are stored in Err.Description.
The following sample macros perform batch processing on all sheets:
(2) FP_GetParticipatsForCurrentUser
Outputs the labels and names of participant units in an application labeled "DEMO" that the currently logged-in user has execution authority for, to the debug window.
Sub PrintParticipants()
Dim Participants As Collection
Dim Participant As FP_Descriptor
Set Participants = FP_GetParticipatsForCurrentUser("DEMO")
For Each Participant In Participants
Debug.Print Participant.Label & " - " & Participant.Name
Next
End Sub
(3) (fusion_place >= 14.1) FP_CallWebApi, FP_CreateWebApiRequest
Executes Importing Dimension Members.
Sub CallUpdateDimension()
Dim request As WebApiRequest
Dim response As WebApiResponse
' Create request object
Set request = FP_CreateWebApiRequest("UPDATE_DIMENSION", "Update SHOHIN dimension")
' parameters
request.addParameter "APPLICATION", "", "DEMO"
request.addParameter "DIMENSION", "", "SHOHIN"
request.addParameter "ROLE", "", "DESIGNER"
' contents
request.addContents "ADD_OR_UPDATE_MEMBER,HDR,LABEL,REMOVE_CHILDREN,NAME:en,NAME:ja,P:#MEMBER_TYPE,P:#LEAF,P:#ACTIVE,PARENT,IS_ROOT"
request.addContents "ADD_OR_UPDATE_MEMBER , DTL, ""T01"", ""TRUE"", """", ""TEST"", ""TEMPLATE"", ""TRUE"", ""TRUE"", ""SHOHIN_KEI"", ""FALSE"""
' Execute Web-API
Set response = FP_CallWebAPI(request)
If response.WebApiCode = API_SUCCESSFUL Then
MsgBox "Success"
Else
MsgBox "Failed" & vbCrLf & response.WebApiCodeString & ":" & response.Message
End If
End Sub
Executes Exporting Dimension Members.
Sub CallExportDimension()
Dim request As WebApiRequest
Dim response As WebApiResponse
' Create request object
Set request = FP_CreateWebApiRequest("EXPORT_DIMENSION", "Export SHOHIN dimension")
' parameters
request.addParameter "APPLICATION", "", "DEMO"
request.addParameter "DIMENSION", "", "SHOHIN"
' Execute Web-API
Set response = FP_CallWebAPI(request)
If response.WebApiCode = API_SUCCESSFUL Then
MsgBox "Success"
Dim returnedContent As Variant
For Each returnedContent In response.ReturnedContents
MsgBox returnedContent
Next returnedContent
Else
MsgBox "Failed" & vbCrLf & response.WebApiCodeString & ":" & response.Message
End If
End Sub