Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Hiding certain footnote texts with VBA in a Word table

Posted on 2012-09-05
Medium Priority
Last Modified: 2012-09-07
Using VBA with Word 2010, I have a table with some footnotes inside certain cells. The footnote texts appear at the bottom of the page.
     From time to time I need to hide some rows in the table, which I do by moving those rows to the end of the table, selecting the rows, and setting the font to just 3 points, the font color to transparent, and the font hidden status to true. That seems far easier to do than to copy the rows and the footnotes into document variables and then restoring them, including formatting and footnotes, from the document variables.  
     With the method of hiding rows at the end and reformatting them to be “invisible,” the rows disappear, but the footnote texts from the hidden rows still appear at the bottom of the page.

     If I could find out which footnotes are in the hidden rows at the end, I suppose I could use something like

     ActiveDocument.Footnotes.Item(i).Reference.Font.Hidden = True
     ActiveDocument.Footnotes.Item(i).Range.Font.Hidden = True

But how could I find the value of the “i" in the above lines?

Thanks for any suggestions.

j.r.a. in Priddis, Alberta
Question by:JohnRobinAllen
  • 4
  • 2
LVL 10

Accepted Solution

tdlewis earned 1400 total points
ID: 38368859
If you leave the rows where they are, select the entire row, and set the Hidden attribute of the font, the rows and the corresponding footnotes disappear except when you display all. (At least that's what happens in Word 2007.)

I've highlighted the places you click on the home tab to change the font to hidden and to toggle "Display All".


Author Comment

ID: 38368989
Thanks for the suggestion. I will work on it and get back to you in about ten minutes.
    Something has been bothering me: sometimes when I worked on the program in the past, the footnotes did disappear when I hid the rows, but not they are not doing so now. Your suggestion might be the reason why it sometimes worked. That would save me a bushel of programming work.
LVL 23

Expert Comment

ID: 38369020
Also, you want to put some code in to ensure hidden text is not set to be printed, otherwise that will defeat the purpose of setting the text font to hidden - e.g.

Application.Options.PrintHiddenText = False
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Closing Comment

ID: 38369336
I tested tdleewis’s solution manually, first by selecting the cell with the footnote and then I pressed Ctrl + D to control the font settings. I clicked the Hidden button to hide the selection, pressed Enter, and the cell disappeared. The footnote remained. That was the problem.
     I then tried selecting all three visible cells (some invisible cells are to the right of the table for sorting purposes). I again manually hid the content of the cells, including the cell with the footnote reference. The cells disappeared and the footnotes remained at the bottom of the page.
     Going back over your response, I saw that you said I should select the entire row to hide, so I did. That worked. The key is to select the whole row, even though what you select may already be hidden.
     Indeed, it worked so well that I am reconsidering my method of hiding rows by moving them to the bottom of the table before I hide them. I would like to simplify life by not using that method, but I have two groups of rows hidden and I want the user to be able to restore one group without the other. The first group of rows hidden is major: the user selects the rows she wants to study, and then she tells the computer to hide all the other rows. The second set of hidden rows is multiple: the user sees that she no longer needs a visible row or two and so deletes them. She deletes more as she continues to work.
     Eventually she will want to undelete the rows she deleted by selecting and deleting, without restoring the first group of rows that she deleted by selecting words to keep while deleting the rows not selected.
     Solution: When a user selects rows to isolate them by hiding the non-selected rows, move the latter (both the rows above the selection and below the selection) to the bottom of the table and hide them à la tdlewis. (I.e., select the entire row, even the parts that are already hidden, before specifying that the selection should be hidden.)
     As the user then selects rows to delete (i.e., by selecting what she wants to delete), then delete them again à la tdlewis but do not bother moving them. When the user wants to restore the latter, we undelete them by selecting all the rows down to the start of the rows hidden at the bottom of the table. We then make the selection visible.
     Later, when the user wants to restore the original rows hidden at the bottom of the table, we restore everything: both groups of hidden stuff. Select the whole table and designate everything visible.
     tdlewis has saved me a lot of trouble not only with the footnote problem, but also with my my hiding code. I’m grateful to him (or her, whichever is correct) and grateful to EE which almost always comes through with a solution to insolvable problems.

     John Robin (Allen)
     Priddis, Alberta, Canada
LVL 10

Expert Comment

ID: 38369493
It's "him".... and you're welcome.

Author Comment

ID: 38370008
irudyk add a comment about ensuring that hidden text should not be set to print, a comment I saw only after I had finished writing my evaluation and had awarded the points.

Thank you very much, irudyk, for the heads-up. After I read your comment, I did indeed check it and, for what it is worth, there seems to be no problem. Rows I had hidden with tdlewis's command do not get printed, at least on my machine. Perhaps that comment applies to some other language than VBA. I do not even know how I would set a font not to print with VBA.


Author Comment

ID: 38378391
I have a further note about selecting rows in a table. I appreciated tdleewis’s suggestion that if I want to hide footnote text at the botttom of a page, I should select an entire row rather than just a cell with a footnote reference number. With the row selected, (Selection.Font.Hidden = True), that solved my problem on hiding footnotes beautifully.
     However, it also raised another problem that took me a couple of days to to solve. When I hide a row (and its footnote in a cell), I also cut and paste the row to the bottom of the table where I hide it. (The reasons why I have to move the rows are not important in this discussion. I just have to move the data.)
     My code worked well until I implemented the solution above. After I began routinely using .RowSelect to select all the cells in a row, I couldn’t move the rows to the end without creating extra empty rows.
     Details: Assume that
          Tbl is the table with the data to hide
          a cell the row(s) to hide is selected,
          EndOfData is the last row in the table after the deletion,
          RowsToHide is the number of rows we will hide,

     Then here is the code that gives the problem:
          With Selection
                  .Rows.Delete  '  Cut won't delete the rows, so I use Copy & Delete
                  .InsertRowsBelow RowsToHide
                  .PasteAndFormat (wdFormatOriginalFormatting)
          End With
     (Then use .RowSelect to select the moved data and then set Selection.Font.Hidden = True)

     The problem with the code is that the .PasteAndFormat command produces strange results. Usually it puts the data beneath the inserted row, which then means I have to go back and delete the empty inserted row. If I do not insert the rows below, then the PasteAndFormat wipes out rows in the table.
     The solution is not to use .RowSelect when selecting the row to copy.
     Specify exactly the cells to select. I have a small function SelectRange() that selects specified cells in a table. When I use that, and copy the selection, the PasteAndFormat works perfectly. Then when I select the row for hiding it, I use tdleewis’s .RowSelect before setting the .Font.Hidden = True.
     I realize that tdlewis never suggested I use SelectRow on a line I want to copy. It is just that I found the command so useful I put it in other places where I wanted to select rows.
     I hope that posting this solution here will prevent others from wasting a couple of days trying to solve the problem.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question