Ich habe ein Makro geschrieben, welches ein Gitternerz mit Lienien erstellt. Abschliessend möchte ich alle diese Linien per Makro noch gruppieren, so dass das erstellte Raster als Ganzes verschoben werden kann. Hier ist mal der Code:
Code: Alles auswählen
Sub Test()
	Gitternetz(5, 50, 100) 'angaben in mm
End sub
Sub Gitternetz(abstand as integer, laenge as integer, hoehe as integer)
	Dim oDoc as object, oFrame as Object
	Dim oTxtCur as object, oFrameCur as Object
		
	Dim oText as object
	Dim oLinie as object
	Dim oCur as object
        Dim size as new com.sun.star.awt.Size    
 	Dim bLine as new com.sun.star.table.BorderLine
 	
 	oShapes = createUnoService("com.sun.star.drawing.ShapeCollection")
    
	oDoc = ThisComponent
	oTxtCur = oDoc.text.createTextCursor()
	
	' Längenangaben von mm in 1/1000cm umrechnen
    abstand = abstand*100
    laenge = laenge*100
    hoehe = hoehe*100
    
    anzahl_hLinien = hoehe / abstand
    anzahl_vLinien = laenge / abstand
    
    ' Horizontale Linien zeichnen und Rasterhinzufügen	
	for horizontal = 0 to anzahl_hLinien
		
		oLinie = oDoc.createInstance("com.sun.star.drawing.LineShape")
		
		size.Width  = laenge
    	        size.Height = 0
    
		With oLinie
    		.LineColor    = rgb(0, 0, 0)
			.AnchorType   = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
			.Size         = size
			.TextWrap     = com.sun.star.text.WrapTextMode.THROUGHT
			.VertOrientPosition = abstand * horizontal + abstand
			.HoriOrientPosition = abstand
			.lineWidth = 0
			.sizeProtect = true
			.MoveProtect = true
		End With
	
    	        oDoc.text.insertTextContent(oTxtCur, oLinie, false)
		oShapes.add(oLinie)
		
	next
	
	
    ' Horizontale Linien zeichnen und Rasterhinzufügen	
	for vertikal = 0 to anzahl_vLinien
		
		oLinie = oDoc.createInstance("com.sun.star.drawing.LineShape")
		
		size.Width  = 0
    	        size.Height = hoehe
    
		With oLinie
    		.LineColor    = rgb(0, 0, 0)
			.AnchorType   = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
			.Size         = size
			.TextWrap     = com.sun.star.text.WrapTextMode.THROUGHT
			.HoriOrientPosition = abstand * vertikal + abstand
			.VertOrientPosition = abstand
			.lineWidth = 0
			.sizeProtect = true
			.MoveProtect = true
		End With	
		
    	        oDoc.text.insertTextContent(oTxtCur, oLinie, false)
		oShapes.add(oLinie)
		
	next
	
	Group = oDoc.text.group(Shapes)
Freundliche Grüsse