Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-10-2021, 12:46 PM
AnBad AnBad is offline Hide Text in a document. Windows 10 Hide Text in a document. Office 2019
Novice
Hide Text in a document.
 
Join Date: Mar 2021
Posts: 5
AnBad is on a distinguished road
Default 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

Reply With Quote
  #2  
Old 03-10-2021, 02:16 PM
Guessed's Avatar
Guessed Guessed is offline Hide Text in a document. Windows 10 Hide Text in a document. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 03-10-2021, 02:38 PM
AnBad AnBad is offline Hide Text in a document. Windows 10 Hide Text in a document. Office 2019
Novice
Hide Text in a document.
 
Join Date: Mar 2021
Posts: 5
AnBad is on a distinguished road
Default

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..
Reply With Quote
  #4  
Old 03-10-2021, 04:40 PM
Guessed's Avatar
Guessed Guessed is offline Hide Text in a document. Windows 10 Hide Text in a document. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #5  
Old 03-10-2021, 11:51 PM
AnBad AnBad is offline Hide Text in a document. Windows 10 Hide Text in a document. Office 2019
Novice
Hide Text in a document.
 
Join Date: Mar 2021
Posts: 5
AnBad is on a distinguished road
Default

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
if a text marked by a bookmark is hidden. Because of the 9s its not working perfekt.

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!!
Reply With Quote
  #6  
Old 03-11-2021, 02:18 AM
Guessed's Avatar
Guessed Guessed is offline Hide Text in a document. Windows 10 Hide Text in a document. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #7  
Old 03-11-2021, 09:19 AM
AnBad AnBad is offline Hide Text in a document. Windows 10 Hide Text in a document. Office 2019
Novice
Hide Text in a document.
 
Join Date: Mar 2021
Posts: 5
AnBad is on a distinguished road
Default

unfortunately,

Code:
If Not MyRange.Bookmarks(x).Range.Font.Hidden = True then
didnt help. I ended up with the same result.

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.

???????
Reply With Quote
  #8  
Old 03-11-2021, 02:44 PM
Guessed's Avatar
Guessed Guessed is offline Hide Text in a document. Windows 10 Hide Text in a document. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #9  
Old 03-14-2021, 03:38 AM
AnBad AnBad is offline Hide Text in a document. Windows 10 Hide Text in a document. Office 2019
Novice
Hide Text in a document.
 
Join Date: Mar 2021
Posts: 5
AnBad is on a distinguished road
Default

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
want work.

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
Thank you for your help.

Kind regards
Reply With Quote
  #10  
Old 03-14-2021, 02:33 PM
Guessed's Avatar
Guessed Guessed is offline Hide Text in a document. Windows 10 Hide Text in a document. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
I didn't work out why you looped through every storytype to only only work with the main body of the document so I left that out of my code.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

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
Hide Text in a document. 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 Text in a document. Hide sentances in a word document michaelgott Word 1 04-19-2012 08:11 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:50 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft