WordVBA, Insert and Pos. Shape with selection.find
15.06.2015 11:13:43
Stefan
folgendes Problem:
der folgende Code sollte ein Bild einfügen, dann formatieren,
danach ausschneiden und an der Position wo der Text mit selection.find
gefunden wird einfügen diese Position auslesen und dann
anhand der ausgelesenen Werte "richtig" Positionieren,
leider funktioniert dies nur auf der 1. Seite des Dokuments.
Wenn sich das Pic nicht auf Seite 1 befindet lest er falsche positionswerte aus.
Ich hoffe irgenjemand kann mir bitte weiterhelfen.
Public Sub test()
Dim strPathPic As String
Dim strPic As String
Dim strBMP As String
Dim Shp As Shape
Dim dblLeft As Double
Dim dblTop As Double
Dim blnYesNo As Boolean
strPathPic = "C:\FHK95\Bilder\"
strBMP = ".bmp"
If MsgBox("Angebot mit Bildern Ja, oder nein?", vbYesNo) _
= vbYes Then blnYesNo = True Else blnYesNo = False
For iCounter = 1 To 15
If iCounter = 1 Then strPic = "Shape_Streifenfundament"
strPAR = strPathPic & strPic & strBMP
Do
If blnYesNo = True Then
Set Shp = ActiveDocument.Shapes.AddPicture(FileName:= _
strPAR, LinkToFile:=False, savewithdocument:=True)
With Shp
.ConvertToInlineShape
.Width = 125
.Height = 50
.Select
End With
Selection.Cut
End If
With Word.Selection.Find
.ClearFormatting
.Text = strPic
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
If blnYesNo = False Then
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
ElseIf blnYesNo = True Then
If .Execute = True Then
Selection.Paste
dblLeft = Shp.Left
dblTop = Shp.Top
' Shp.Delete
' Selection.Paste
Shp.WrapFormat.Type = wdWrapThrough
Shp.Left = dblLeft + 365
Shp.Top = dblTop + 45
Else: Exit Do
End If
End If
End With
Loop
Next iCounter
End Sub