AW: WordVBA auf Seitennummer von Beschriftung zugreife
13.03.2015 14:32:31
Beschriftung
Hallo Snoophot
Habe mal ein wenig gebastelt:
Sub Makro1()
Dim rngErgebnis As Range, spage, gesuchteAbbildung As String, spagedoc, isec As Integer, _
bGefunden As Boolean
Set rngErgebnis = ActiveDocument.Content.Duplicate
gesuchteAbbildung = InputBox("Abbildung: ")
gesuchteAbbildung = "Abbildung " & gesuchteAbbildung & vbCr
rngErgebnis.Find.Style = ActiveDocument.Styles("Beschriftung")
For Each w In rngErgebnis.Words
With rngErgebnis.Find
.Forward = True
.Wrap = wdFindStop
.Execute
bGefunden = .Found
End With
If bGefunden Then
Debug.Print rngErgebnis
Debug.Print gesuchteAbbildung
If rngErgebnis = gesuchteAbbildung Then
With Selection.Find
.Text = rngErgebnis
.Replacement.Text = rngErgebnis
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
spage = Selection.Information(wdActiveEndPageNumber)
spagedoc = Selection.Information(wdNumberOfPagesInDocument)
isec = Selection.Sections(1).Index
If ActiveDocument.Sections.Count > 1 Then
MsgBox rngErgebnis & "wurde gefunden im Abschnitt " & isec & " auf Seite " & spage & _
_
" von " & spagedoc, vbInformation, "Seiteninfo"
Else
MsgBox rngErgebnis & "wurde gefunden auf Seite " & spage & " von " & spagedoc, _
vbInformation, "Seiteninfo"
End If
Else
End If
End If
Next
End Sub