ajhez
05-12-2015, 08:08 AM
Hi all
I am currently working on creating a word document containing a table which is populated by data from an excel sheet.
I have managed to figure out how to get the various data over from excel into word, but the next stage is to run a macro that essentially cleans up the word document by removing text that is not necessary based on the data carried over from the excel sheet.
The word document contains a table at the begging (with the 2nd column being populated by the data from the excel sheet) underneath the table there are paragraphs of text relating to the data in each row of the table. However, where the data inputted from the excel sheet = 0 then i want to delete the related paragraph of text from the document.
So far i have individually bookmarked the entire range of each of theparagraphs i want to delete. Ideally what i want to do is 'if the data/text in row 1 column 2 = "0" then delete 'bookmark x' if it is anything else then i want it to keep the paragraph as normal.
Below is what i've tried so far (apologies for the basic nature of it):
Sub BTest()
Dim bnName As Range
Set bnName = ActiveDocument.Bookmarks("bmName").Range
If ActiveDocument.Tables(1).Cell(1, 2).Range.Text = "0" Then
ActiveDocument.Bookmarks("bmName").Range.Delete
Else
End If
End Sub
Any ideas? Thanks all!
I am currently working on creating a word document containing a table which is populated by data from an excel sheet.
I have managed to figure out how to get the various data over from excel into word, but the next stage is to run a macro that essentially cleans up the word document by removing text that is not necessary based on the data carried over from the excel sheet.
The word document contains a table at the begging (with the 2nd column being populated by the data from the excel sheet) underneath the table there are paragraphs of text relating to the data in each row of the table. However, where the data inputted from the excel sheet = 0 then i want to delete the related paragraph of text from the document.
So far i have individually bookmarked the entire range of each of theparagraphs i want to delete. Ideally what i want to do is 'if the data/text in row 1 column 2 = "0" then delete 'bookmark x' if it is anything else then i want it to keep the paragraph as normal.
Below is what i've tried so far (apologies for the basic nature of it):
Sub BTest()
Dim bnName As Range
Set bnName = ActiveDocument.Bookmarks("bmName").Range
If ActiveDocument.Tables(1).Cell(1, 2).Range.Text = "0" Then
ActiveDocument.Bookmarks("bmName").Range.Delete
Else
End If
End Sub
Any ideas? Thanks all!