Page.SetFormulas 方法 (Visio)

會設定一個或多個儲存格的公式。

語法

expressionSetFormulas( _SID_SRCStream()_ , _formulaArray()_ , _Flags_ )

表達 代表 Page 對象的變數。

參數

名稱 必要/選用 資料類型 描述
SID_SRCStream () 必要項目 整數 識別要修改之儲存格的資料流。
formulaArray () 必要 Variant 要指派給識別的儲存格之公式。
Flags 必要項目 整數 會影響 SetFormulas 行為的旗標。

傳回值

整數

註解

SetFormulas 方法的行為就像 Formula 屬性,但是有一點例外,就是可以使用這個方法一次設定很多儲存格的公式,而不是一次設定一個儲存格的公式。

針對 Page 物件,您可以使用 SetFormulas 方法,在頁面或主圖形的任何一組圖形中設定任何單元格集的結果。 您可以在 SID_SRCStream () 中傳遞整數陣列,告訴 SetFormulas 方法您想要設定的儲存格。 SID_SRCStream () 是 2 位元組整數的一維陣列。

為 Page 物件SID_SRCStream () 應該是 n>= 1 之 4 n 個 2 位元組整數的一維數位。 SetFormulas 方法會將數據流解譯為:

{sheetID, sectionIdx, rowIdx, cellIdx }n

其中的 sheetID 為頁面或主圖形上的 Shape 物件的 ID 屬性 (要修改此頁面或主圖形的儲存格結果)。

如果專案中的 sheetIDvisInvalShapeID (-1) ,或 sectionIdx 的底部位元組是 visSectionInval (255) ,SetResults 方法就會忽略該專案。 這是因為相同的 SID_SRCStream () 陣列可用於對 SetFormulas、GetFormulas 的數個呼叫,以及呼叫端只需要在呼叫之間對數據流進行微幅變更的類似方法。

formulaArray () 參數應該是 1 <= m 變體的一維陣列。 每個 Variant 都應該是 StringString 的參考或 空白。 如果 formulaArray (i) 是空的, 則 i 'th 單元格會設定為 formulaArray (j) 中的公式,其中 j 是最近一個不是空白之專案的索引。 如果沒有先前不是空的專案,則不會更改對應的單元格。 如果指定的公式少於單元格, ( m<n) ,i 'th 單元格 i>m 會設定為與選擇將 m 'th 單元格設定為相同的公式。 因此,若要將許多儲存格設定為相同的公式,您只需要傳遞一份公式。

Flags 參數應是下列值的位元遮罩。

常數 描述
visSetBlastGuards &H2 覆寫目前的儲存格值 (即使這些值有受到保護)。
visSetTestCircular &H4 測試儲存格循環參考的建立。
visSetUniversalSyntax &H8 公式在通用語法中。

SetFormulas 方法傳回的值是SID_SRCStream () 中已成功處理的項目數目。 如果 i<n 個項目處理正確,但 第 i + 1 個項目發生錯誤, 則 SetFormulas 方法會引發例外狀況並傳回 i。 否則會傳回 n

範例

下列宏示範如何使用 SetFormulas 方法。 它假設有一個作用中的 Microsoft Office Visio 頁面,其中至少有三個圖形。 它會使用 GetFormulas 方法來取得圖案 1 的寬度、圖案 2 的高度,以及圖案 3 的角度。 然後,它會使用 SetFormulas 將圖案 1 的寬度設定為圖案 2 的高度,並將圖案 2 的高度設定為圖案 1 的寬度。 圖案 3 的角度會保持不變。

這個範例會使用 Page 物件的 GetFormulas 方法來取得三個儲存格公式,並使用相同物件的 SetFormulas 方法來設定公式。 輸入陣列對於每一個儲存格會有四個空位,Master 物件也是同樣的情形。 如果是 ShapeStyle 物件,則每一個儲存格只需要三個空位 (區段、資料列及儲存格)。

 
Public Sub SetFormulas_Example() 
 
 On Error GoTo HandleError 
 
 Dim aintSheetSectionRowColumn(1 To 3 * 4) As Integer 
 aintSheetSectionRowColumn(1) = ActivePage.Shapes(1).ID 
 aintSheetSectionRowColumn(2) = visSectionObject 
 aintSheetSectionRowColumn(3) = visRowXFormOut 
 aintSheetSectionRowColumn(4) = visXFormWidth 
 
 aintSheetSectionRowColumn(5) = ActivePage.Shapes(2).ID 
 aintSheetSectionRowColumn(6) = visSectionObject 
 aintSheetSectionRowColumn(7) = visRowXFormOut 
 aintSheetSectionRowColumn(8) = visXFormHeight 
 
 aintSheetSectionRowColumn(9) = ActivePage.Shapes(3).ID 
 aintSheetSectionRowColumn(10) = visSectionObject 
 aintSheetSectionRowColumn(11) = visRowXFormOut 
 aintSheetSectionRowColumn(12) = visXFormAngle 
 
 'Return the formulas of the cells. 
 Dim avarFormulaArray() As Variant 
 ActivePage.GetFormulas aintSheetSectionRowColumn, avarFormulaArray 
 
 'Use SetFormulas to: 
 ' - Set the width of shape 1 to height of shape 2. 
 ' - Set height of shape 2 to width of shape 1. 
 ' Note: avarFormulaArray() is indexed from 0 to 2. 
 Dim varTemp As variant 
 varTemp = avarFormulaArray(0) 
 avarFormulaArray(0) = avarFormulaArray(1) 
 avarFormulaArray(1) = varTemp 
 
 'Pass the same array back to SetFormulas that we 
 'just passed to GetFormulas, leaving angle alone. By setting 
 'the sheet ID entry in the third slot of the 
 'aintSheetSectionRowColumn array to visInvalShapeID, 
 'we tell SetFormulas to ignore that slot. 
 aintSheetSectionRowColumn (9) = visInvalShapeID 
 
 'Tell Microsoft Visio to set the formulas of the cells. 
 ActivePage.SetFormulas aintSheetSectionRowColumn, avarFormulaArray, 0 
 
 Exit Sub 
 
HandleError: 
 
 MsgBox "Error" 
 
 Exit Sub 
 
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應