Freigeben über


Gewusst wie: Programmgesteuertes Kopieren und Einfügen von Shapes in ein Visio-Dokument

Sie können Shapes programmgesteuert auf einer Seite eines Dokuments kopieren und auf einer neuen Seite im selben Dokument einfügen.Sie können wählen, ob Sie die Shapes an der Standardposition (in der Mitte des aktiven Fensters) oder an derselben Koordinatenposition wie auf der ursprünglichen Seite einfügen möchten.

Kopieren und Einfügen von Shapes

Weitere Informationen zum Objektmodell finden Sie in der VBA-Referenzdokumentation für die Methoden Microsoft.Office.Interop.Visio.Shape.DrawRectangle, Microsoft.Office.Interop.Visio.Shape.DrawOval, Microsoft.Office.Interop.Visio.Shape.Copy und Microsoft.Office.Interop.Visio.Shape.Paste sowie für das Microsoft.Office.Interop.Visio.VisCutCopyPasteCodes.visCopyPasteNormal-Flag.

So kopieren Sie Shapes in die Mitte einer anderen Seite

  • Im folgenden Beispiel wird gezeigt, wie die Shapes von der ersten Seite kopiert und in die Mitte der zweiten Seite eingefügt werden.

    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);
    }
    

Kopieren und Einfügen von Shapes an der gleichen Position

Weitere Informationen zum Objektmodell finden Sie in der VBA-Referenzdokumentation für die Methoden Microsoft.Office.Interop.Visio.Shape.DrawRectangle, Microsoft.Office.Interop.Visio.Shape.DrawOval, Microsoft.Office.Interop.Visio.Shape.Copy und Microsoft.Office.Interop.Visio.Shape.Paste sowie für das Microsoft.Office.Interop.Visio.VisCutCopyPasteCodes.visCopyPasteNoTranslate-Flag.

Wenn Sie das Format der eingefügten Informationen steuern und (optional) einen Link zur Quelldatei erstellen möchten (z. B. ein Microsoft Office Word-Dokument), verwenden Sie die PasteSpecial-Methode.

So kopieren Sie Shapes mit ihrer Position auf eine andere Seite

  • Im folgenden Beispiel wird gezeigt, wie die Shapes von der ersten Seite kopiert und auf der zweiten Seite an ihrer ursprünglichen Koordinatenposition eingefügt werden.

    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);
    }
    

Siehe auch

Aufgaben

Gewusst wie: Programmgesteuertes Hinzufügen von Shapes zu Visio-Dokumenten

Konzepte

Übersicht über das Visio-Objektmodell

Arbeiten mit Visio-Shapes

Weitere Ressourcen

Visio-Projektmappen