GetFormulasU 方法 (Visio)Page.GetFormulasU method (Visio)

會傳回很多儲存格的公式。Returns the formulas of many cells.

語法Syntax

expressionexpression. GetFormulasU( _SID_SRCStream()_ , _formulaArray()_ )

_運算式_代表**Page** 物件的變數。expression A variable that represents a Page object.

參數Parameters

名稱Name 必要/選用Required/Optional 資料類型Data type 描述Description
SID_SRCStream()SID_SRCStream() 必要Required IntegerInteger 識別要查詢之儲存格的資料流。Stream identifying cells to be queried.
formulaArray ()formulaArray() 必要Required VariantVariant 輸出參數。Out parameter. 會接收查詢儲存格公式的陣列。Array that receives formulas of queried cells.

傳回值Return value

Nothing

註解Remarks

GetFormulasU方法就像Cell物件的FormulaU屬性, 但您可以使用它一次取得多個儲存格的公式, 而不是一次一個儲存格。The GetFormulasU method is like the FormulaU property of a Cell object, except you can use it to obtain the formulas of many cells at once, rather than one cell at a time. GetFormulasU 方法是 GetResults 方法的特殊化,可以用來取得儲存格公式或結果。The GetFormulasU method is a specialization of the GetResults method, which can be used to obtain cell formulas or results. 設定呼叫 GetFormulasU 方法所涉及的工作比設定 GetResults 方法所涉及的工作稍微少一些。Setting up a call to the GetFormulasU method involves slightly less work than setting up the GetResults method.

您可以使用 GetFormulasU 方法,在頁面或主圖形的任何一組圖形中,取得任何一組儲存格的通用語法中的公式。You can use the GetFormulasU method to get formulas in universal syntax of any set of cells in any set of shapes of the page or master.

SID_SRCStream () 是2位元組整數的陣列。SID_SRCStream() is an array of 2-byte integers. SID_SRCStream () 應該是 4 n 2 位元組整數的一維陣列, 其中_n_ >= 1。SID_SRCStream() should be a one-dimensional array of 4 n 2-byte integers for n >= 1. GetFormulasU方法會將_SID_SRCStream ()_ 解釋為:The GetFormulasU method interprets SID_SRCStream() as:

{sheetID, sectionIdx, rowIdx, cellIdx}n

其中的 sheetID 為頁面或主圖形上的 Shape 物件的 ID 屬性 (需要此頁面或主圖形的儲存格公式)。where sheetID is the ID property of the Shape object on the page or master whose cell formula is desired.

注意

如果專案中的_sheetID_是visInvalShapeID (-1), 或是_SectionIdx_的底部位元組是visSectionInval (255), 則會忽略該專案, 並在對應的結果陣列專案中傳回空的 variant。If the sheetID in an entry is visInvalShapeID (-1) or if the bottom byte of sectionIdx is visSectionInval (255), the entry will be ignored and an empty variant will be returned in the corresponding results array entry. 這是因為在呼叫者對GetFormulasUSetFormulas及類似方法的呼叫中, 可以使用相同的_SID_SRCStream ()_ 陣列, 而只需要對通話之間的資料流程進行次要變更。The reason for this is that the same SID_SRCStream() array can be used on several calls to GetFormulasU, SetFormulas, and similar methods with the caller only needing to make minor changes to the stream between calls.

如果GetFormulasU方法成功, formulaArray () 會傳回從0到_n_ -1 的_n_個變化的一維陣列。If the GetFormulasU method succeeds, formulaArray() returns a one-dimensional array of n variants indexed from 0 to n - 1. 每個 variant 都以字串傳回公式。Each variant returns a formula as a string. formulaArray () 是由GetFormulasU方法所指派的輸出參數, 它會將擁有權傳送給呼叫者。formulaArray() is an out parameter that is allocated by the GetFormulasU method, which passes ownership back to the caller. 來電者最終應該在傳回的陣列上執行SafeArrayDestroy程式。The caller should eventually perform the SafeArrayDestroy procedure on the returned array. 請注意, SafeArrayDestroy程式會對清除陣列專案所參照的變化有負面影響, 因此會將GetFormulasU方法傳回的任何字串解除配置。Note that the SafeArrayDestroy procedure has the side effect of clearing the variants referenced by the array's entries, hence deallocating any strings the GetFormulasU method returns. (Microsoft Visual Basic 和 Microsoft Visual Basic for Applications 會為您進行這項處理。)如果_formulaArray ()_ 為Null, 則GetFormulasU方法會失敗。(Microsoft Visual Basic and Microsoft Visual Basic for Applications take care of this for you.) The GetFormulasU method fails if formulaArray() is Null.

注意

從 Microsoft Visio 2000 開始, 您可以使用本機和通用名稱來參照 Visio 圖形、主控形狀、檔、頁面、列、附加元件、儲存格、超連結、樣式、字型、主圖形快捷方式、UI 物件和圖層。Beginning with Microsoft Visio 2000, you can use both local and universal names to refer to Visio shapes, masters, documents, pages, rows, add-ons, cells, hyperlinks, styles, fonts, master shortcuts, UI objects, and layers. 使用者命名圖形時, 例如, 使用者指定的是本機名稱。When a user names a shape, for example, the user is specifying a local name. 從 Microsoft Office Visio 2003 開始, ShapeSheet 試算表只會在儲存格公式和值中顯示通用名稱。Beginning with Microsoft Office Visio 2003, the ShapeSheet spreadsheet displays only universal names in cell formulas and values. (在先前版本中, 通用名稱在使用者介面中不可見)。(In prior versions, universal names were not visible in the user interface.)

身為開發人員,如果您不希望每次將方案本土化時就要變更名稱,可以在程式中使用通用名稱。As a developer, you can use universal names in a program when you don't want to change a name each time a solution is localized. 使用本機語法時,使用 GetFormulas 方法可取得一個以上的公式。Use the GetFormulas method to get more than one formula when you are using local syntax. 若是使用通用語法,請使用 GetFormulasU 方法取得一個以上的公式。Use the GetFormulasU method to get more than one formula when you are using universal syntax.

範例Example

下列宏會示範如何使用GetFormulasU方法。The following macro shows how to use the GetFormulasU method. 它假設有使用中的 Visio 頁面, 其至少有三個圖案。It assumes that there is an active Visio page that has at least three shapes on it. 它會使用GetFormulasU來取得圖案1的寬度、圖案2的高度, 以及圖案3的角度。It uses GetFormulasU to get the width of shape 1, the height of shape 2, and the angle of shape 3.

這個範例會使用Page物件的GetFormulasU方法來取得三個儲存格公式輸入陣列每個儲存格都有四個槽, 也就是Master物件一樣。This example uses the GetFormulasU method of the Page object to get three cell formulas The input array has four slots for each cell, as it also would for Master objects. 如果是 ShapeStyle 物件,則每一個儲存格只需要三個空位 (區段、資料列及儲存格)。For Shape or Style objects, only three slots would be needed for each cell (section, row, and cell).

 
Public Sub GetFormulasU_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.GetFormulasU aintSheetSectionRowColumn, avarFormulaArray 
 
 Debug.Print "Shape 1 width is "; avarFormulaArray(0) 
 Debug.Print "Shape 2 height is "; avarFormulaArray(1) 
 Debug.Print "Shape 3 angle is "; avarFormulaArray(2) 
 
 
Exit Sub 
 
HandleError: 
 MsgBox "Error" 
Exit Sub 
 
End Sub

支援和意見反應Support and feedback

有關於 Office VBA 或這份文件的問題或意見反應嗎?Have questions or feedback about Office VBA or this documentation? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.