Check alle échte Black Friday-deals Ook zo moe van nepaanbiedingen? Wij laten alleen échte deals zien

Range probleem booksmarks in VBA

Pagina: 1
Acties:

  • unXist
  • Registratie: November 2010
  • Laatst online: 28-10 15:36
Hallo,

Ik ben bezig met een word document waarin ik meerdere stukken tekst of delen van een tabel m.b.v. een checkbox wil laten tonen/verbergen door die stukken te bookmarken. Ik heb hiervoor een macro gevonden die dit zou moeten kunnen. Het lukt me om 1 bookmark te verbergen/tonen door de naam van de bookmark in deze regel in te vullen:

code:
1
Set orange = ActiveDocument.Bookmarks("bookmarkName").Range


Ik wil echter meerdere bookmarks tegelijkertijd tonen/verbergen maar zodra ik een extra bookmarkName toevoeg krijg ik een compileerfout.

Weet iemand hoe de code moet zijn om dit te kunnen?

Groet, Mark

N.B. de gehele code van de macro:

Macro
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Option Explicit 
 
Sub CheckBox1_Change() 
    Call ShowHideTable 
End Sub 
 
Sub ShowHideTable() 
    With Selection 
        .GoTo What:=wdGoToTable, Which:=wdGoToNext, _ 
        Count:=1, Name:="" 
        .Tables(1).Select 
    End With 
    If CheckBox1.Value = True Then 
        With Selection.Font 
            .Hidden = True 
        End With 
        With ActiveWindow.View 
            .ShowHiddenText = False 
            .ShowAll = False 
        End With 
    Else 
        With Selection.Font 
            .Hidden = False 
        End With 
        With ActiveWindow.View 
            .ShowHiddenText = True 
            .ShowAll = True 
        End With 
        With Selection 
            .Collapse direction:=wdCollapseStart 
            .MoveLeft unit:=wdCharacter, Count:=1 
        End With 
    End If 
End Sub 
 
 
 ' the other View properties
 ' if you want to still see paragraph marks, you
 ' must explicitly turn it on = True
 '  .ShowAnimation = True
 '  .Draft = False
 '  .WrapToWindow = False
 '  .ShowPicturePlaceHolders = False
 '  .ShowFieldCodes = False
 '  .ShowBookmarks = False
 '  .FieldShading = wdFieldShadingWhenSelected
 '  .ShowTabs = False
 '  .ShowSpaces = False
 '  .ShowParagraphs = False
 '  .ShowHyphens = False
 '  .ShowHiddenText = False
 '  .ShowAll = True
 '  .ShowDrawings = True
 '  .ShowObjectAnchors = False
 '  .ShowTextBoundaries = False
 '  .ShowHighlight = True
 '  .DisplayPageBoundaries = True
 '  .DisplaySmartTags = True
 
 ' this is to do the same thing with a bookmark ("mytext")
 ' using a second checkbox (Checkbox2)
 
Sub CheckBox2_Change() 
    Call ShowHideBookmark 
End Sub 
 
 
Sub ShowHideBookmark() 
    Dim orange As Range 
    Set orange = ActiveDocument.Bookmarks("mytext").Range 
    If CheckBox2.Value = True Then 
        With orange.Font 
            .Hidden = True 
        End With 
        With ActiveWindow.View 
            .ShowHiddenText = False 
            .ShowAll = False 
        End With 
    Else 
        With orange.Font 
            .Hidden = False 
        End With 
        With ActiveWindow.View 
            .ShowHiddenText = True 
            .ShowAll = True 
        End With 
    End If 
End Sub

  • DukeBox
  • Registratie: April 2000
  • Laatst online: 23:39

DukeBox

loves wheat smoothies

Denk dat je dat met een array moet oplossen.

Duct tape can't fix stupid, but it can muffle the sound.


  • unXist
  • Registratie: November 2010
  • Laatst online: 28-10 15:36
DukeBox schreef op vrijdag 26 september 2014 @ 10:06:
Denk dat je dat met een array moet oplossen.
Hoe zou zo`n oplossing vorm krijgen, waar in de code? Ik ben nog niet heel bekend met VBA.

  • DukeBox
  • Registratie: April 2000
  • Laatst online: 23:39

DukeBox

loves wheat smoothies

Als je niet heel bekend met met VBA dan zou je deze kennis natuurlijk kunnen vergaren of anders kun je misschien in V&A iemand vinden die dat voor je kan doen.

Duct tape can't fix stupid, but it can muffle the sound.