• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to DISABLE unused bookmarks in WORD

Rahul Agarwal

New Member
I am copying a set of data from various excel files into a Word Document at specified bookmarks. If any file is absent during run then at that specified bookmark next line character is printing which is creating space between the data. How to remove this blank space if content for that bookmark is not present. This time I'm using the below mentioned code. In the attached image under "HELP NEEDED" section there is a lots of gap between Simulation and Performance as there is a bookmark between them and its data is not present with us. It is desired to omit this blank space due to unused bookmarks.

Code:
ActiveDocument.Bookmarks(BM_name).Select
sheet.Sheets("Weekly Update").Range(Cell_name).Borders.LineStyle = xlNone
s = Replace(Trim(sheet.Sheets("Weekly Update").Range(Cell_name).Value), Chr(10) & Chr(10), "")
Selection.TypeText Text:=s
 

Attachments

  • Capture.PNG
    Capture.PNG
    16.6 KB · Views: 2
Hi Rahul,
you have not posted the most relevant part of your code which cycles through the bookmarks and relates them to the range you are copying.
That said, from what you have posted, i'm struggling to see why you can't just skip the bookmark you have no data for:
Code:
If Sheet.Sheets("Weekly Update").Range(Cell_name).Value <> "" Then
    'your code to copy data
End If

If this was helpful, please click Like! in the bottom right.

Stevie
 
Back
Top