#1
|
|||
|
|||
Hide Text in a document.
Hi,
I have a document with some simple word spreadsheets. I gave all of them a bookmark name so that I can hide and unhide the spreadsheets. Everything works fine only some sheets got the value: ActiveDocument.Bookmarks(MyRange.Bookmarks(x).Name ).Range.Font.Hidden = 9999999 It should -1 (hidden) or 0 (not hidden). But some have 9999999 I did some digging and realized that the spreadsheets with faulty 9999999 are showing at fonts/effects full filled marks everywhere from "Strikethrough" up to "Hidden" (not in this picture, they are all empty her cause I could find a pic online). That cant be, cause nothing is strikenthrough... I cant find why. What is going on here? I need this cause I want to create a list with all visible Bookmarks via VBA. Thank you |
#2
|
||||
|
||||
When there is a mixed response to the question, the result is undefined - hence the 9s
This is indicating that some of the bookmark range is hidden and some of it isn't. Generally this is visible in the dialogs like the Font one you showed as a three-state checkbox - Empty box says this is false - Ticked box says this is true - Black filled box says parts are true and parts are false
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Yes, you are right.
But there is no mixed value. Even when I am setting everything to unchecked. When I am opening fonts/effect again all boxes are filled black again. But why, I cant find why that happens.. |
#4
|
||||
|
||||
Without seeing your document I can only guess as to why you have a mixed selection/range.
Perhaps you have protected content which is not changing when you try to change it. For instance locked CCs or grouped content. Are there any floating text boxes? You may also have tracked revisions which could be playing a role in this.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
Hi,
indeed there are floating text boxes. But in other spreadsheets too. So I well check this tonight. Nothing is protected. I am checking with Code:
If ActiveDocument.Bookmarks(MyRange.Bookmarks(x).Name).Range.Font.Hidden = False Then Is there a way to check only the first or two letters/words of the text within a bookmark if they are hidden? If so the whole text between the bookmark is hidden or not. This might give the correct resulat -1 or 0. Thank you!! |
#6
|
||||
|
||||
If any part of the range is hidden then you could use
Code:
If Not MyRange.Bookmarks(x).Range.Font.Hidden = True then
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#7
|
|||
|
|||
unfortunately,
Code:
If Not MyRange.Bookmarks(x).Range.Font.Hidden = True then I must admit that I want to mark the table and the following sitebreake to hide not just the text and table but the whole site with the table. Otherwise the site would be blank when the text is hidden and not the sitebreak. For some reason this is working fine untile the table has more than 16 rows. On the other hand I have tables which are bigger then 16 rows. I tried a new word document, write everything again. Always the same problem with this table. When I mark the table with the sitebreak and try to give a new fontstyle everything works. But when I call again the font style no font is in the box as if there are diffrent fonts. But there are not. ??????? |
#8
|
||||
|
||||
It is not clear what exactly you are trying to achieve so it might help if you provide larger chunks of your code so we can see what else is going on. Or maybe a sample doc with tables of varying sizes to test your code on.
Bookmarks tend to be fiddly and if you are adding to the start/end of a bookmark it is possible that content you think is in or out may actually not be. I would recommend you explore using Rich Text Content Controls to 'tag' your ranges and you may find this works better for your hide/show code.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#9
|
|||
|
|||
Hello,
I am trying to put all NOT hidden Bookmarks into an Array. But it want work, because of the 9s-fault, because Code:
ActiveDocument.Bookmarks(MyRange.Bookmarks(x).Name).Range.Font.Hidden = False I solved this issue by adding some Bookmarks_dummy into the faulty ranges with only view words in these. Now the code recognizes the Bookmarks and with repace() I delete the "_dummy". At the end I got my list. But its not the way as it should be. I would prefer a clean solution. I use this code (here without my dummy-Replasement) Code:
Sub useFormInhaltFuellen() 'nach Reihenfolge im Doku sortiert 'ohne Kopf- und Fußzeile Dim aDoc As Word.Document Dim nDoc As Word.Document Dim x As Long, i As Long Dim MyRange As Word.Range Dim v As String Set aDoc = ActiveDocument If aDoc.Bookmarks.Count < 1 Then MsgBox "kein Textmarken im Dokument enthalten!" Exit Sub End If i = 0 ReDim strArray(aDoc.Bookmarks.Count, 0) For Each MyRange In aDoc.StoryRanges Do While Not MyRange Is Nothing v = MyRange.StoryType If MyRange.StoryType = wdMainTextStory Then For x = 1 To MyRange.Bookmarks.Count If ActiveDocument.Bookmarks(MyRange.Bookmarks(x).Name).Range.Font.Hidden = False Then strArray(i, 0) = MyRange.Bookmarks(x).Name i = i + 1 End If Next x End If Set MyRange = MyRange.NextStoryRange Loop Next 'Listbox1 eintragen ufInhalt.ListBox1.List = strArray End Sub Kind regards |
#10
|
||||
|
||||
OK, try this code which collapses the range to test whether the bookmarked range starts with hidden formatting.
Code:
Sub useFormInhaltFuellen() 'nach Reihenfolge im Doku sortiert 'ohne Kopf- und Fußzeile Dim aDoc As Word.Document, aBkmk As Bookmark, v As String Dim aRng As Range, strArray() As String Set aDoc = ActiveDocument If aDoc.Bookmarks.Count = 0 Then MsgBox "kein Textmarken im Dokument enthalten!" Exit Sub End If For Each aBkmk In aDoc.Bookmarks Set aRng = aBkmk.Range aRng.Collapse Direction:=wdCollapseStart If Not aRng.Font.Hidden Then v = v & "|" & aBkmk.Name End If Next aBkmk v = Mid(v, 2) 'remove the leading separator strArray = Split(v, "|") ufInhalt.ListBox1.List = strArray 'Listbox1 eintragen End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to text heading1 text heading1 text? How to collapse or hide text in the middle of a line. | TImer | Word | 7 | 08-10-2020 12:52 AM |
Conditionally hide parts of a document | elaineAda | Word VBA | 0 | 04-01-2019 10:00 PM |
How to manage (display/hide) parts of the text within a document via table of content | Curby | Word | 2 | 06-30-2016 12:29 AM |
Page nos in footers - how to hide mid document | willynilly | Word | 2 | 11-22-2013 07:21 AM |
Hide sentances in a word document | michaelgott | Word | 1 | 04-19-2012 08:11 PM |