1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| Sub A111111EnregistrerPagesWeb()
' A partir d'une page word où ne sont enregistrées que des adresses de pages web, enregistrer ces même pages web au format ".docx"
' On Error Resume Next
On Error GoTo erreur
Dim MyText0 As String
MyText0 = "http://"
Dim count As Integer
Selection.HomeKey Unit:=wdStory ' place le curseur en debut du document
count = 0
' on détermine le nombre d'adresse dans la page
With ActiveDocument.Content.Find
Do While .Execute(FindText:=MyText0, Format:=False, MatchCase:=False, MatchWholeWord:=True) = True
count = count + 1
Loop
End With
Dim i As Integer
Dim MyText1 As String
Dim MyText2 As String
Dim MyText3 As String
Selection.HomeKey Unit:=wdStory ' place le curseur en debut du document
i = 1
For i = 1 To count
Selection.Collapse Direction:=wdCollapseStart
With Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindContinue
.Execute FindText:="http://"
End With
Selection.EndKey Unit:=wdLine ' place le curseur en fin du document
Selection.TypeText Text:="&&&"
Next i
For i = 1 To count
' On sélectionne l'adresse htm qui commence par "http://" et se termine par "&&&"
With Selection.Find
.ClearFormatting
.Text = "http://"
.MatchWildcards = 0
.Forward = 1
.Replacement.Text = ""
.Replacement.ClearFormatting
.Execute ' recherche du mot1
.Text = "&&&"
Selection.Extend ' etendre la selection
.Execute ' atteindre le mot2
End With
MyText1 = Selection.Text
' On sélectionne la page à ouvrir et on lui attribue un nom d'enregistrement
MyText2 = Replace(MyText1, "&&&", "")
MyText3 = "MaPageWeb"
Selection.Delete
Documents.Open fileName:=MyText2 ' on ouvre la page web
' ChangeFileOpenDirectory "C:\Users\MyName\Desktop\Mon dossier"
ActiveDocument.SaveAs fileName:=MyText3 & i, FileFormat:= _
wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
ActiveDocument.Close
erreur:
Next i
End Sub |
Partager