共用方式為


HOW TO:在 Visio 文件中複製並貼上圖形

您可以自行撰寫程式,將文件頁面上的圖形複製貼到同一份文件的另一個新頁面上。 您可以選擇將圖形貼到預設位置 (使用中視窗的中央),或是貼到與原始頁面一樣的座標位置。

複製並貼上圖形

如需物件模型 (Object Model) 的詳細資訊,請參閱 Microsoft.Office.Interop.Visio.Shape.DrawRectangleMicrosoft.Office.Interop.Visio.Shape.DrawOvalMicrosoft.Office.Interop.Visio.Shape.CopyMicrosoft.Office.Interop.Visio.Shape.Paste 方法以及 Microsoft.Office.Interop.Visio.VisCutCopyPasteCodes.visCopyPasteNormal 旗標的 VBA 參考文件。

若要將圖形複製至另一頁的中央

  • 在下列範例中,會示範如何從第一個頁面複製圖形,並貼到第二個頁面的中央。

    Me.Application.Documents.Add("")
    Dim copyPage As Visio.Page
    Dim pastePage As Visio.Page
    Dim rectangle As Visio.Shape = Nothing
    Dim oval As Visio.Shape = Nothing
    
    Dim visioPages As Visio.Pages = Me.Application.ActiveDocument.Pages
    
    visioPages.Add()
    
    Try
        copyPage = visioPages(1)
        rectangle = copyPage.DrawRectangle(1.1, 2.2, 4.5, 6.7)
        oval = copyPage.DrawOval(1, 8.75, 3.5, 6.25)
    Catch ex As Exception
        System.Windows.Forms.MessageBox.Show(ex.Message)
    End Try
    
    Try
        pastePage = visioPages(2)
        rectangle.Copy(Visio.VisCutCopyPasteCodes.visCopyPasteNormal)
        pastePage.Paste(Visio.VisCutCopyPasteCodes.visCopyPasteNormal)
        oval.Copy(Visio.VisCutCopyPasteCodes.visCopyPasteNormal)
        pastePage.Paste(Visio.VisCutCopyPasteCodes.visCopyPasteNormal)
    Catch ex As Exception
        System.Windows.Forms.MessageBox.Show(ex.Message)
    End Try
    
    this.Application.Documents.Add("");
    Visio.Page copyPage;
    Visio.Page pastePage;
    Visio.Shape rectangle = null;
    Visio.Shape oval = null;
    
    Visio.Pages visioPages = this.Application.ActiveDocument.Pages;
    
    visioPages.Add();
    
    try
    {
        copyPage = visioPages[1];
        rectangle = copyPage.DrawRectangle(1.1, 2.2, 4.5, 6.7);
        oval = copyPage.DrawOval(1, 8.75, 3.5, 6.25);
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show(ex.Message);
    }
    
    try
    {
        pastePage = visioPages[2];
        rectangle.Copy(Visio.VisCutCopyPasteCodes.visCopyPasteNormal);
        pastePage.Paste(Visio.VisCutCopyPasteCodes.visCopyPasteNormal);
        oval.Copy(Visio.VisCutCopyPasteCodes.visCopyPasteNormal);
        pastePage.Paste(Visio.VisCutCopyPasteCodes.visCopyPasteNormal);
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show(ex.Message);
    }
    

複製圖形並以相同位置貼上圖形

如需物件模型的詳細資訊,請參閱 Microsoft.Office.Interop.Visio.Shape.DrawRectangleMicrosoft.Office.Interop.Visio.Shape.DrawOvalMicrosoft.Office.Interop.Visio.Shape.CopyMicrosoft.Office.Interop.Visio.Shape.Paste 方法以及 Microsoft.Office.Interop.Visio.VisCutCopyPasteCodes.visCopyPasteNoTranslate 旗標的 VBA 參考文件。

如果需要控制貼上資訊的格式以及 (選擇性) 建立來源檔案 (例如 Microsoft Office Word 文件) 的連結,請使用 PasteSpecial 方法。

若要將圖形和圖形位置複製到另一頁

  • 在下列範例中,會示範如何從第一個頁面複製圖形,並以其原始座標位置貼到第二個頁面。

    Me.Application.Documents.Add("")
    Dim copyPage As Visio.Page
    Dim pastePage As Visio.Page
    Dim rectangle As Visio.Shape = Nothing
    Dim oval As Visio.Shape = Nothing
    
    Dim visioPages As Visio.Pages = Me.Application.ActiveDocument.Pages
    
    visioPages.Add()
    
    Try
        copyPage = visioPages(1)
        rectangle = copyPage.DrawRectangle(1.1, 2.2, 4.5, 6.7)
        oval = copyPage.DrawOval(1, 8.75, 3.5, 6.25)
    Catch ex As Exception
        System.Windows.Forms.MessageBox.Show(ex.Message)
    End Try
    
    Try
        pastePage = visioPages(2)
        rectangle.Copy(Visio.VisCutCopyPasteCodes.visCopyPasteNoTranslate)
        pastePage.Paste(Visio.VisCutCopyPasteCodes.visCopyPasteNoTranslate)
        oval.Copy(Visio.VisCutCopyPasteCodes.visCopyPasteNoTranslate)
        pastePage.Paste(Visio.VisCutCopyPasteCodes.visCopyPasteNoTranslate)
    Catch ex As Exception
        System.Windows.Forms.MessageBox.Show(ex.Message)
    End Try
    
    this.Application.Documents.Add("");
    Visio.Page copyPage;
    Visio.Page pastePage;
    Visio.Shape rectangle = null;
    Visio.Shape oval = null;
    
    Visio.Pages visioPages = this.Application.ActiveDocument.Pages;
    
    visioPages.Add();
    
    try
    {
        copyPage = visioPages[1];
        rectangle = copyPage.DrawRectangle(1.1, 2.2, 4.5, 6.7);
        oval = copyPage.DrawOval(1, 8.75, 3.5, 6.25);
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show(ex.Message);
    }
    
    try
    {
        pastePage = visioPages[2];
        rectangle.Copy(Visio.VisCutCopyPasteCodes.visCopyPasteNoTranslate);
        pastePage.Paste(Visio.VisCutCopyPasteCodes.visCopyPasteNoTranslate);
        oval.Copy(Visio.VisCutCopyPasteCodes.visCopyPasteNoTranslate);
        pastePage.Paste(Visio.VisCutCopyPasteCodes.visCopyPasteNoTranslate);
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show(ex.Message);
    }
    

請參閱

工作

HOW TO:將圖形加入至 Visio 文件

概念

Visio 物件模型概觀

使用 Visio 圖案

其他資源

Visio 方案