von Florian79 » Fr, 27.01.2012 03:07
Hallo zusammen
ich stehe vor einem kleinen Problem. Ich habe eine Impress Vorlage, in der auf bestimmte Seiten immer eine Grafik (Screenshot) eingefügt werden muss. Da das Formatieren jedes Screenshots auf Dauer doch nervig ist, wäre für diese Aufgabe ein Makro super.
Das Makro wird über einen Button in der Symbolleiste aufgerufen und soll dann ein Menü öffnen zur Auswahl des entsprechendes Screenshots und diesen Screenshot eben genau auf der Seite, auf der ich mich gerade befinde einfügen. Die Screenshots sollen am Ende auch direkt in das Dokument eingebunden sein und müssen damit jeweils mit einem individuellen Namen versehen werden.
Mein Makro funktioniert so weit ganz gut, einzig das automatische Einfügen auf die aktuelle Seite stellt mich gerade vor gewaltige Probleme. Gebe ich im Makro bei der Variablen SLIDE die entsprechende Seitenzahl vor, dann funktioniert es genau so wie ich es will, aber ich weiß einfach nicht, wie ich es hin bekomme, dass die Seitenzahl automatisch ermittelt und weiter verwendet wird.
Falls einer einen Rat kennt, wäre ich äußerst dankbar
Danke
Florian
Code: Alles auswählen
Sub InsertPicture
Dim Slide as integer
Dim Screenshot as string
oDoc = ThisComponent
Slide = 1
oDrawPage = oDoc.getDrawPages().getByIndex(Slide)
Screenshot = "Screenshot" &Slide
oFilePickerDlg = createUnoService( "com.sun.star.ui.dialogs.FilePicker" )
oFilePickerDlg.appendFilter("Images","*.jpg;*.jpeg;*.gif;*.bmp;")
oFilePickerDlg.appendFilter("All files","*.*")
oFilePickerDlg.MultiSelectionMode = False
nResult = oFilePickerDlg.execute
If nResult = 0 Then Exit Sub
cFile = oFilePickerDlg.Files(0)
cUrl = ConvertToUrl( cFile )
cUrl = LoadGraphicIntoDocument( oDoc, cUrl, Screenshot )
oShape = MakeGraphicObjectShape( oDoc, MakePoint( 0, 3000 ), MakeSize( 28000, 18000 ) )
oDrawPage.add( oShape )
oShape.GraphicURL = cUrl
End Sub
Function LoadGraphicIntoDocument( oDoc As Object, cUrl As String, cInternalName As String ) As String
oBitmaps = oDoc.createInstance( "com.sun.star.drawing.BitmapTable" )
oBitmaps.insertByName( cInternalName, cUrl )
cNewUrl = oBitmaps.getByName( cInternalName )
LoadGraphicIntoDocument = cNewUrl
End Function
Function MakePoint( ByVal x As Long, ByVal y As Long ) As com.sun.star.awt.Point
oPoint = createUnoStruct( "com.sun.star.awt.Point" )
oPoint.X = x
oPoint.Y = y
MakePoint = oPoint
End Function
Function MakeSize( ByVal width As Long, ByVal height As Long ) As com.sun.star.awt.Size
oSize = createUnoStruct( "com.sun.star.awt.Size" )
oSize.Width = width
oSize.Height = height
MakeSize = oSize
End Function
Function MakeRectangleShape( oDoc As Object, Optional oPosition As com.sun.star.awt.Point, Optional oSize As com.sun.star.awt.Size ) As com.sun.star.drawing.RectangleShape
oShape = oDoc.createInstance( "com.sun.star.drawing.RectangleShape" )
If Not IsMissing( oPosition ) Then
oShape.Position = oPosition
EndIf
If Not IsMissing( oSize ) Then
oShape.Size = oSize
EndIf
MakeRectangleShape = oShape
End Function
Function MakeGraphicObjectShape( oDoc As Object, Optional oPosition As com.sun.star.awt.Point, Optional oSize As com.sun.star.awt.Size ) As com.sun.star.drawing.GraphicObjectShape
oShape = oDoc.createInstance( "com.sun.star.drawing.GraphicObjectShape" )
If Not IsMissing( oPosition ) Then
oShape.Position = oPosition
EndIf
If Not IsMissing( oSize ) Then
oShape.Size = oSize
EndIf
MakeGraphicObjectShape = oShape
End Function
Moderation,4: verschoben in BASIC-Unterbereich, wo alle Makro-Fragen hin gehören; Betreff angepasst
Hallo zusammen
ich stehe vor einem kleinen Problem. Ich habe eine Impress Vorlage, in der auf bestimmte Seiten immer eine Grafik (Screenshot) eingefügt werden muss. Da das Formatieren jedes Screenshots auf Dauer doch nervig ist, wäre für diese Aufgabe ein Makro super.
Das Makro wird über einen Button in der Symbolleiste aufgerufen und soll dann ein Menü öffnen zur Auswahl des entsprechendes Screenshots und diesen Screenshot eben genau auf der Seite, auf der ich mich gerade befinde einfügen. Die Screenshots sollen am Ende auch direkt in das Dokument eingebunden sein und müssen damit jeweils mit einem individuellen Namen versehen werden.
Mein Makro funktioniert so weit ganz gut, einzig das automatische Einfügen auf die aktuelle Seite stellt mich gerade vor gewaltige Probleme. Gebe ich im Makro bei der Variablen SLIDE die entsprechende Seitenzahl vor, dann funktioniert es genau so wie ich es will, aber ich weiß einfach nicht, wie ich es hin bekomme, dass die Seitenzahl automatisch ermittelt und weiter verwendet wird.
Falls einer einen Rat kennt, wäre ich äußerst dankbar
Danke
Florian
[code]
Sub InsertPicture
Dim Slide as integer
Dim Screenshot as string
oDoc = ThisComponent
Slide = 1
oDrawPage = oDoc.getDrawPages().getByIndex(Slide)
Screenshot = "Screenshot" &Slide
oFilePickerDlg = createUnoService( "com.sun.star.ui.dialogs.FilePicker" )
oFilePickerDlg.appendFilter("Images","*.jpg;*.jpeg;*.gif;*.bmp;")
oFilePickerDlg.appendFilter("All files","*.*")
oFilePickerDlg.MultiSelectionMode = False
nResult = oFilePickerDlg.execute
If nResult = 0 Then Exit Sub
cFile = oFilePickerDlg.Files(0)
cUrl = ConvertToUrl( cFile )
cUrl = LoadGraphicIntoDocument( oDoc, cUrl, Screenshot )
oShape = MakeGraphicObjectShape( oDoc, MakePoint( 0, 3000 ), MakeSize( 28000, 18000 ) )
oDrawPage.add( oShape )
oShape.GraphicURL = cUrl
End Sub
Function LoadGraphicIntoDocument( oDoc As Object, cUrl As String, cInternalName As String ) As String
oBitmaps = oDoc.createInstance( "com.sun.star.drawing.BitmapTable" )
oBitmaps.insertByName( cInternalName, cUrl )
cNewUrl = oBitmaps.getByName( cInternalName )
LoadGraphicIntoDocument = cNewUrl
End Function
Function MakePoint( ByVal x As Long, ByVal y As Long ) As com.sun.star.awt.Point
oPoint = createUnoStruct( "com.sun.star.awt.Point" )
oPoint.X = x
oPoint.Y = y
MakePoint = oPoint
End Function
Function MakeSize( ByVal width As Long, ByVal height As Long ) As com.sun.star.awt.Size
oSize = createUnoStruct( "com.sun.star.awt.Size" )
oSize.Width = width
oSize.Height = height
MakeSize = oSize
End Function
Function MakeRectangleShape( oDoc As Object, Optional oPosition As com.sun.star.awt.Point, Optional oSize As com.sun.star.awt.Size ) As com.sun.star.drawing.RectangleShape
oShape = oDoc.createInstance( "com.sun.star.drawing.RectangleShape" )
If Not IsMissing( oPosition ) Then
oShape.Position = oPosition
EndIf
If Not IsMissing( oSize ) Then
oShape.Size = oSize
EndIf
MakeRectangleShape = oShape
End Function
Function MakeGraphicObjectShape( oDoc As Object, Optional oPosition As com.sun.star.awt.Point, Optional oSize As com.sun.star.awt.Size ) As com.sun.star.drawing.GraphicObjectShape
oShape = oDoc.createInstance( "com.sun.star.drawing.GraphicObjectShape" )
If Not IsMissing( oPosition ) Then
oShape.Position = oPosition
EndIf
If Not IsMissing( oSize ) Then
oShape.Size = oSize
EndIf
MakeGraphicObjectShape = oShape
End Function[/code]
[color=#800000]Moderation,4[/color]: verschoben in BASIC-Unterbereich, wo alle Makro-Fragen hin gehören; Betreff angepasst