0
votes

I have been trying to figure out how to hide 2 rows in Microsoft word. I know that it does not have the same features as excel, but what I am doing needs to be done in word. I currently have a table and I wanted to hide 2 rows. Here is the basic info: - The table has a total of 17 rows.
- I want to hide rows 16 & 17. - Row 16 had 5 columns - Row 17 has 3 columns. - the table cannot have a title... - Microsoft word --> Office 16

This table is being pulled into excel using a different VBA script and the parameters of that script require that this table still contains 17 rows. I have been trying to figure out how to minimize/hide these rows in a word for a couple of days now. I have found several pieces of code online and I get errors with each code.

I am very much a noob when it comes to VBA.

Here is the code I have tried to utilize:

 Private Sub CommandButton1_Click()

   Dim BBGEarlyAppr As Range
   Dim BBGEarlyAppr2 As Range
      With ActiveDocument.Tables(1)
          Set BBGEarlyAppr = .Rows(7).Range
          BBGEarlyAppr.End = .Rows(41).Range.End
      End With

      With ActiveDocument.Tables(1)
          Set BBGEarlyAppr2 = .Rows(60).Range
          BBGEarlyAppr2.End = .Rows(68).Range.End
       End With

      With BBGEarlyAppr.Font
           .Hidden = True
      End With
      With BBGEarlyAppr2.Font
          .Hidden = True
      End With
  End Sub

I get an error at BBGEarlyAppr.End = .Rows(41).Range.End "the requested member of the collection does not exist"

Is this because rows are off? Also, hiding the font does not appear to remove the font within the cells...

Any help or explanation would be greatly appreciated. I

1
You say your table has 17 rows but you are referencing row 41. - Brian M Stafford
OH okay. I get it now. But, when it un the code. the cells just remain unchanged. I have a feeling its a setting. - Joseph Fresco
Click on the ΒΆ symbol on the Ribbon's Home tab to turn off Word's display of formatting marks etc. Unless they're turned off, you will still see any hidden content. As this is an application-level setting, not a document-level setting, the same issue will affect anyone else who views your document. Indeed, if a given user has Word's 'print hidden text' option switched on, the hidden content will print even if it's not displayed! - macropod

1 Answers

0
votes

I'm not seeing any problem with your macro. In File>Options>Display, if you have the Hidden Text or All options set, hidden text will remain visible, but will have a fine dotted line drawn below it. Turn off that option to see the true effect of your code.