HERBERS Excel-Forum - das Archiv
WordVBA, Insert and Pos. Shape with selection.find
Stefan

Servus,
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

AW: WordVBA, Insert and Pos. Shape with selection.find
JoWE

Hallo Stefan,
da bietet sich als Anlaufstelle so'n Excel-Forum natürlich spontan an.... :-)
Gruß
Jochen

AW: WordVBA, Insert and Pos. Shape with selection.find
Stefan

Servus,
dadurch dass ich mein Word aus Excel heraus starte und der Code auch im Excel steht und beides ja "relativ" ähnlich ist bietet sich ein Excel Forum welches kompetent scheint an. Ja

AW: ah ja,..
JoWE

und nochmal Hallo,
nun, das war weder in der Betreffzeile noch in Deinem Beitrag erkennbar.
Egal, ich stelle Deine Frage für alle nochmal offen.
Gruß
Jochen

AW: ah ja,..
Stefan

Zur Info, ursprünglicher Thread https://www.herber.de/forum/messages/1430430.html

WordVBA, Insert and Pos. Shape with selection.find
Stefan

Servus,
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

AW: WordVBA, Insert and Pos. Shape with selection.find
JoWE

Hallo Stefan,
da bietet sich als Anlaufstelle so'n Excel-Forum natürlich spontan an.... :-)
Gruß
Jochen

AW: WordVBA, Insert and Pos. Shape with selection.find
Stefan

Servus,
dadurch dass ich mein Word aus Excel heraus starte und der Code auch im Excel steht und beides ja "relativ" ähnlich ist bietet sich ein Excel Forum welches kompetent scheint an. Ja

AW: ah ja,..
JoWE

und nochmal Hallo,
nun, das war weder in der Betreffzeile noch in Deinem Beitrag erkennbar.
Egal, ich stelle Deine Frage für alle nochmal offen.
Gruß
Jochen

AW: ah ja,..
Stefan

Zur Info, ursprünglicher Thread https://www.herber.de/forum/messages/1430430.html

Bewerten Sie hier bitte das Excel-Portal