Visio使用VBA以编程方式设置页面方向

时间:2011-06-16 11:57:59

标签: vba visio visio-vba

我需要使用VBA以可编程方式将Page Orientation属性更改为“Landscape”值。目前,我正在使用以下代码:

Application.ActivePage.PageSheet.CellsU("PrintPageOrientation").Formula = 2

但这仅适用于打印机而非我正在更改的页面。

我一直在Microsoft documentation寻找合适的Cell,但我没有取得任何成功。

感谢您的帮助。

3 个答案:

答案 0 :(得分:1)

只需设置页面的高度和宽度即可。景观/肖像没有单元格。

John ...... Visio MVP

答案 1 :(得分:0)

我知道这是一个古老的问题,但是对于其他寻求答案的人: 在Visio中更改PrintPageOrientation单元格 确实会更改文档中页面的方向,而不仅仅是打印。

对于变量名称为vzpVisioPage的页面对象,以下行将设置横向方向:

vzpVisioPage.PageSheet.CellsSRC(visSectionObject, visRowPrintProperties, _
    visPrintPropertiesPageOrientation).FormulaForceU = "2"

要制作合法尺寸的页面,请使用以下几行:

vzpVisioPage.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageWidth).FormulaU = "14 in"
vzpVisioPage.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageHeight).FormulaU = "16.5 in"

答案 2 :(得分:0)

基于上述SmrtGrunt的解决方案,我创建了一个C#示例:

///above in includes
using Visio = Microsoft.Office.Interop.Visio;

///above in private fields
private Visio.Page ActivePage;

///above in constructor
ActivePage = Globals.ThisAddIn.Application.ActivePage;

/// <summary>
/// Sets the currently open document to landscape (if not already set)
/// </summary>
public void SetOrientationToLandscape()
{
    var orientation = ActivePage.PageSheet.CellsSRC[(short) Visio.VisSectionIndices.visSectionObject,
        (short) Visio.VisRowIndices.visRowPrintProperties,
        (short) Visio.VisCellIndices.visPrintPropertiesPageOrientation].FormulaU;

    //If orientation flag isn't set to 'landscape'
    if (orientation != ((int)Visio.tagVisCellVals.visPPOLandscape).ToString())
    {
        //Landscape
        ActivePage.PageSheet.CellsSRC[(short) Visio.VisSectionIndices.visSectionObject,
            (short) Visio.VisRowIndices.visRowPrintProperties,
            (short) Visio.VisCellIndices.visPrintPropertiesPageOrientation].FormulaU = ((int)Visio.tagVisCellVals.visPPOLandscape).ToString();

        var currentWidth = ActivePage.PageSheet.CellsSRC[(short) Visio.VisSectionIndices.visSectionObject,
            (short) Visio.VisRowIndices.visRowPage, (short) Visio.VisCellIndices.visPageWidth].FormulaU;
        var currentHeight = ActivePage.PageSheet.CellsSRC[(short) Visio.VisSectionIndices.visSectionObject,
            (short) Visio.VisRowIndices.visRowPage, (short) Visio.VisCellIndices.visPageHeight].FormulaU;


        ActivePage.PageSheet.CellsSRC[(short) Visio.VisSectionIndices.visSectionObject,
            (short) Visio.VisRowIndices.visRowPage, (short) Visio.VisCellIndices.visPageWidth].FormulaU = currentHeight;
        ActivePage.PageSheet.CellsSRC[(short) Visio.VisSectionIndices.visSectionObject,
            (short) Visio.VisRowIndices.visRowPage, (short) Visio.VisCellIndices.visPageHeight].FormulaU = currentWidth;
    }
}