• hello fellows,


    I have a question.... i have a document(generated with data from excel) and everytime I generate a report sometimes i have to create new file or append the existing file, i have bookmarks in file, but when i'm trying to append the file he don't clean the bookmarks, i want to know how to clean the bookmarks.



    huges


    Pedro Moura

  • Re: bookmarks


    Hi Pedro,


    The code is by no means elegant but it works

    Code
    Sub Test()
    On Error Resume Next
    For i = ActiveDocument.Bookmarks.Count To 1 Step -1
    temp = ActiveDocument.Bookmarks.Count
    ActiveDocument.Bookmarks(temp).Delete
    Next i
    End Sub


    Hope this helps


    John

  • Re: bookmarks


    thanks for the help Johnccc,


    but i do'nt know wich tipe is the variable temp is an object? is a String?
    i try this code, but when i append the bookmark i have an error


    this is the function


    this is the code i try to put working


    huges

  • Re: bookmarks


    Quote from Andy Pope

    When you say clean do you mean DELETE or CLEAR CONTENT?


    John's code is removing all the bookmarks when appending, which will cause your code to fail.


    sorry my explanation was not correct, when i say clean is to clear the content of the bookmark.
    Huges

  • Re: bookmarks


    Hi,


    Surely the code

    Code
    .Bookmarks("local").Range.Text = ""


    Where "local" can be replaced by temp from my code should get rid of the text but leave the bookmark in place??


    HTH


    John

  • Re: bookmarks



    Hi,
    I did that on my code. I create a function


    Code
    Function clean_content_of_Bookmarks()
      With wordDoc
          .Bookmarks(bookmarkname).Range.Text = ""
        ' do the same to all bookmarks in the document
      End With
    End Function


    but it didn't clear the content, and wrote the text after the content in the docuement.

  • Re: bookmarks


    Hi,


    You need to put this into a "sub" not a function.


    Look at your code, you currently set each bookmark with the code earlier in your post. Can you alter it as follows:-


    Unfortunately due to my works IT policy I cannot test this as I am unable to open Word from Excel. Give it a try though.


    John

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!