Consulting

Results 1 to 8 of 8

Thread: Find and replace

  1. #1
    VBAX Regular
    Joined
    Aug 2008
    Posts
    16
    Location

    Find and replace

    Hallo,

    Wie kan mij helpen,
    ik heb het volgende probleem, ik moet copy /paste een bestand invoegen in een word document maar dit bestand wat ik invoeg heeft al paginanummers
    Blz. 1 van 6 Deze regels staan niet in de footer maar in het document
    Is het mogelijk met VBA om deze blz. regels in het hele document te verwijderen.
    groet,
    Rien


    Quote Originally Posted by Oorang
    English Version Courtesy Google
    Who can help me,
    I have the following problem: I have to copy/paste a file into a word document but it has a page number (Ex. 1 of 6). Is it possible with VBA to remove the page numbers from the document?

    Last edited by rien; 03-20-2009 at 11:27 PM.

  2. #2
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Sub Aantal_Blz()
        Dim No_Of_Pages As Long
        Dim myloop As Long
        Dim myrange As Range
        No_Of_Pages = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
        For myloop = 1 To No_Of_Pages
            Set myrange = ActiveDocument.Range(Start:=0, End:=0)
            With myrange.Find
                .ClearFormatting
                .Text = "Blz. " & myloop & " van " & No_Of_Pages
                With .Replacement
                     .ClearFormatting
                     .Text = ""
                End With
                .Execute Replace:=wdReplaceAll, _
                Format:=True, MatchCase:=True, _
                MatchWholeWord:=True
            End With
        Next myloop
    End Sub
    Charlize

  3. #3
    VBAX Regular
    Joined
    Aug 2008
    Posts
    16
    Location

    Smile Find and Replace

    Charlize,

    Sorry, dat ik de post niet gemeld had als Thread Solved. Ik zal jouw oplossing toepassen. Het enige wat ik dan nog moet doen in dit document is de naam van het rapport weer op elke pagina als eerste regel zien te krijgen.
    Misschien heb je daar nog een oplossing voor, ik heb het geprobeerd met search "rapport", daarna 1 regel naar boven en dan een CTRL+Enter om een harde pagina in te voegen. Maar dit werkt niet echt goed.

    groet,Rien

  4. #4
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Sub Aantal_Blz()
        Dim No_Of_Pages As Long
        Dim myloop As Long
        Dim myrange As Range
        Dim mytitle As String
        No_Of_Pages = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
        For myloop = 1 To No_Of_Pages
            Set myrange = ActiveDocument.Range(Start:=0, End:=0)
            With myrange.Find
                .ClearFormatting
                .Text = "Blz. " & myloop & " van " & No_Of_Pages
                With .Replacement
                    .ClearFormatting
                    .Text = ""
                End With
                .Execute Replace:=wdReplaceAll, _
                Format:=True, MatchCase:=True, _
                MatchWholeWord:=True
            End With
        Next myloop
        'Ga naar begin van het document
        Selection.HomeKey unit:=wdStory
        'Eerste maal zoeken naar titel want hier moet geen
        'harde pagina worden gezet
        Beep
        mytitle = InputBox("Geef exacte rapporttitel ...", "Zoek titel ...")
        With Selection.Find
            .Text = mytitle
            .Forward = True
            .Format = False
            .Execute
        End With
        'ga naar het einde van de regel (zin)
        Selection.EndKey unit:=wdLine
        Do
            With Selection.Find
                'Aanpassen aan de titel van je eigen rapport
                .Text = mytitle
                .Forward = True
                .Format = False
            End With
            'Als titel niet meer gevonden wordt, zal lus eindigen
            'dmv de exit sub
            If Selection.Find.Execute = False Then
                MsgBox "Alle titels werden behandeld", vbInformation, "Titels verwerken ..."
                Selection.HomeKey unit:=wdStory
                Exit Sub
            Else
                'Titel wel gevonden, ga naar begin van de regel
                'voeg pagina einde toe en ga naar einde van de regel (zin)
                Selection.HomeKey unit:=wdLine
                Selection.InsertBreak Type:=wdPageBreak
                Selection.EndKey unit:=wdLine
            End If
        Loop
    End Sub
    Charlize

  5. #5
    VBAX Regular
    Joined
    Aug 2008
    Posts
    16
    Location

    Wink find and replace

    Charlize,

    Ik weet dat het niet gebruikelijk is, maar kan ik de bestanden naar jouw persoonlijk mailen, het in te voegen bestand is namelijk vertrouwelijk (bedrijfsgegevens).
    Ik heb namelijk de indruk dat mijn vraag (probleem) niet helemaal duidelijk is.

    groet,
    Rien

    ps. bedankt voor alle moeite

  6. #6

    Lightbulb useful tips

    This is great! It really shows me where to expand my blog. I think that sometime in the future I might try to write a book to go along with my blog, but we will see…Good post with useful tips and ideas

  7. #7
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Quote Originally Posted by Gossioii3
    This is great! It really shows me where to expand my blog. I think that sometime in the future I might try to write a book to go along with my blog, but we will see…Good post with useful tips and ideas
    ?

    What's the meaning ?

    Charlize

  8. #8
    VBAX Regular
    Joined
    Aug 2008
    Posts
    16
    Location

    Smile thread is afgehandeld

    Hallo Charlize,

    Ik heb geen idee wie deze gebruiker is en wat hij wil. Ik ben bijzonder goed geholpen en de tread is afgemeld.

    met vriendelijke groet,
    Rien

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •