VBA controls menus on the menu bar (such as page settings and printing)

Source: Internet
Author: User
'Try the following Code See if you can meet your requirements?
Sub test ()
'English names of various tools in the view Toolbar
'Worksheet menu bar 'indicates the worksheet menu bar.
Application. commandbars ("worksheet menu bar"). Enabled = false
'Formatting format Toolbar
Application. commandbars ("formatting"). Visible = false
'Standard 'indicates commonly used Toolbar
Application. commandbars ("standard"). Visible = falsae
'Drawing indicates the Drawing toolbar.
Application. commandbars ("Drawing"). Visible = false
'Control toolbox indicates the control toolbox
Application. commandbars ("control toolbox"). Visible = false
'Reviewing indicates a review tool
Application. commandbars ("reviewing"). Visible = false
Application. commandbars ("Kingsoft translation"). Visible = false
'Dispalyformulabar indicates the editing bar
Application. displayformulabar = false
Application. commandbars ("Visual Basic"). Visible = false
Application. commandbars ("Web"). Visible = false
Application. commandbars ("protection"). Visible = false
Application. commandbars ("borders"). Visible = false
Application. commandbars ("forms"). Visible = false
Application. commandbars ("formula auditing"). Visible = false
Application. commandbars ("Watch window"). Visible = false
'Pivottable' indicates a pivot table.
Application. commandbars ("resumttable"). Visible = false
'Chart indicates a chart
Application. commandbars ("chart"). Visible = false
'Picture indicates the image
Application. commandbars ("picture"). Visible = false
Application. commandbars ("Exit Design Mode"). Visible = false
'External data indicates external data
Application. commandbars ("external data"). Visible = false
'Ply' indicates the worksheet tag.
Application. commandbars ("Ply"). Enabled = false
For each cbar in commandbars
Debug. Print cbar. Name, cbar. namelocal, cbar. Visible
Next
End sub private sub test ()
Dim I as long
Dim wordapp as new word. Application
Dim cbar as office. commandbar
Dim cctl as office. commandbarcontrol

Set cbar = wordapp. commandbars (27) 'bar Index
For each cctl in cbar. Controls
If cctl. ID = 2041 or cctl. ID = 2604 then' 2041 Control ID
Cctl. Enabled = false
End if
Next

Set cbar = nothing
Set cctl = nothing
Set wordapp = nothing
End sub
This is a blocking method. As for how many bar IDs you want to shield, the Control ID is as follows:

Word menu list


Commandbar ID _ Control Caption

Text11_2520 _ create a blank document (& B)
Listen 23_open (& O )...
1_3 _ save (& S)
20173738 _ email recipient (& M)
20172521 _ print (& P)
Preview 109 _ print preview (& V)
Limit 4026_simplified Chinese conversion (& R )...
Limit 2566 _ spelling and syntax (& S )...
Listen 21_cut (& T)
Listen 19 _ copy (& C)
Continue 22_paste (& P)
Limit 108 _ format brush (& F)
Limit 128 _ unrecoverable (& U)
2017129 _ unrecoverable (& R)
20171576 _ HYPERLINK (& I )...
2017916_" table and border "toolbar (& T)
1_333 _ insert table (& I )...
1_142 _ insert an Excel worksheet (& I)
Limit 2872 _ change the text direction (& C)
Drawing 204 _ plot (& D)
20173900 _ show/hide edit tags (& S)
Listen 1733 _ display ratio (& Z ):
1_984_microsoft word help (& H)
1_1 _ Kingsoft Overlord
2_1732 _ style (& S ):
2_1728 _ font (& F ):
2_1731 _ font size (& F ):
2_3659 _ keyboard language (& K)
2_113 _ bold (& B)
2_114 _ skew (& I)
2_3962 _ underline (& U)
2_3517 _ character border (& C)
2_3518 _ character shading (& C)
2_386 _ character Scaling (& C)
2_123 _ alignment on both ends (& J)
2_122 _ Center (& C)
2_121_right alignment (& R)
2_2792 _ distributed alignment (& D)
2_1846 _ from left to right (& L)
2_1847 _ from right to left (& R)
2_11 _ No. (& N)
2_12 _ project symbol (& B)
2_3473 _ reduce indentation (& D)
2_3472 _ increase the indentation (& I)
2_401 _ font color (& F)
3_2059 _ Drawing a table (& W)
3_2060 _ Erasure (& E)
3_1724 _ border line (& B)
3_2622 _ Border width (& B)
3_2628 _ border color (& B)
3_203 _ border (& B)
3_2947 _ Background color (& S)
3_1_3 _ insert table (& T)
3_798 _ merge cells (& M)
3_800 _ Split the cell (& P )...
3_30461 _ cell alignment (& G)
3_2068 _ evenly distribute rows (& N)
3_2067 _ evenly distribute columns (& Y)
3_107 _ automatic table format (& F )...
3_2816 _ hide a virtual box (& G)
3_3157 _ ascending (&)
3_3158 _ descending order (& C)
3_226_auto sum (&)
4_3272 _ data form (& D)
4_3124 _ management domain (& M)
4_213_add record (&)
4_214 _ delete a record (& D)
4_3157 _ Ascending Order (&)
4_3158-_descending Order (& C)
4_216_database (& D )...
4_215_update domain (& U)
4_183 _ search in the domain (& F)
4_244 _ main document (& M)
5_30013 _ plotting (& R)
5_182 _ select object (& S)
5_688 _ free rotation (& T)
5_30177 _ custom image (& U)
5_130 _ straight line (& L)
5_243 _ arrow (&)
5_1111_rectangle (& R)
5_1119 _ elliptic (& O)
5_139 _ text box (& X)
5_318 _ vertical text box (& V)
5_1031 _ wordart (& W )...
5_682 _ clip art (& C )...
5_1691 _ fill color (& F)
5_1692 _ line color (& L)
5_401 _ font color (& F)
5_692 _ linetype (& L)
5_693 _ dotted line (& D)
5_694 _ arrow style (&)
5_394 _ shadow (& S)
5_339 _ 3D effect (& 3)
6_219 _ edit box (& E)
6_220_check box (& C)
6_221 _ combo box (& C)
6_1607 _ attributes (& R)
6_2059 _ Drawing a table (& W)
6_333 _ insert table (& I )...
6_3174 _ text box (& F)
6_223 _ display domain shading (& S)
6_225 _ protection form (& P)
7_178 _ disable full screen display (& C)
8_299 _ adjust the margin (&)
8_922_disable image (& C)
9_186 _ macro (& M )...
9_184 _ recording a new macro (& R )...
9_3627 _ Security (& S )...
9_1695_visual Basic Editor (& V)
9_548 _ control toolbox (& O)
9_1605 _ design mode (& D)
9_3631_microsoft Script Editor (& W )...
10_2186 _ stop recording (& R)
10_185 _ pause recording (& P)
11_30076 _ insert merged domain
11_30077 _ insert a word Field
11_163 _ display domain/value (& S)
11_154 _ first record (& F)
11_155 _ previous record (& P)
11_1730 _ record (& R )...
11_156 _ next record (& N)
11_157 _ end record (& L)
11_246 _ email Merge (& R )...
11_161 _ merge error checks (& E)
11_159 _ Merge document (& M)
11_160 _ merge to printer (& M)
11_245 _ merge option (& M )...
11_183 _ search in the domain (& F)
11_162 _ data form (& D)
13_263_microsoft Excel (& E)
13_267_microsoft PowerPoint (& P)
13_262_microsoft mail (& M)
13_cmd_microsoft access (&)
13_266_microsoft Visual FoxPro (& F)
13_269_microsoft Project (& R)
13_265_microsoft schedule + (& S)
13_268_microsoft publisher (& B)
14_30423 _ Automatic Image Collection (&)
14_1554 _ page number (& P)
14_743 _ page number (& N)
14_2384 _ set page number format (& F)
14_125 _ date (& D)
14_126 _ time (& T)
14_247 _ page settings (& U )...
14_248 _ hide the body (& H)
14_250_link to the previous section (& L)
14_237 _ display the header/footer (& S)
14_238 _ previous header (& P)
14_239 _ next header (& N)
14_924 _ close (& C)
15_132 _ upgrade (& P)
15_demo_downgrade (& D)
15_136 _ downgrade to body (& B)
15_134 _ move up (& U)
15_135 _ move down (& M)
15_expansion _ expand (& E)
15_138 _ fold (& C)
15_71 _ show as Title 1 (& 1)
15_72 _ show to Title 2 (& 2)
15_73 _ show to Title 3 (& 3)
15_74 _ show to Title 4 (& 4)
15_75 _ show to Title 5 (& 5)
15_76 _ show as Title 6 (& 6)
15_77 _ show to Title 7 (& 7)
15_826 _ all (& L)
15_rows _ view only the first line (& F)
15_252 _ display format (& S)
15_230 _ master document view (& M)
15_1633 _ fold sub-document (& C)
15_231 _ create a sub-document (& C)
15_232 _ delete a sub-document (& D)
15_233 _ import sub-document (& I)
15_235_merge sub-documents (& M)
15_234 _ molecular splitting document (& S)
15_236 _ Protection Sub-document (& P)
16_2521 _ print (& P)
16_172 _ magnifiers (& M)
16_5 _ single page (& O)
16_177 _ multiple pages (& M)
16_1733 _ display ratio (& Z ):
16_179 _ ruler (& R)
16_173 _ reduce one page (& S)
16_1612 _ full screen display (& U)
16_923_close (& C)
16_124 _ What is this? (& T)
17_2520 _ create blank document (& B)
17_23 _ open (& O )...
17_3 _ save (& S)
17_21 _ Cut (& T)
17_19 _ copy (& C)
17_22 _ paste (& P)
17_128 _ unrecoverable (& U)
17_11 _ No. (& N)
17_12 _ project symbol (& B)
17_14 _ reduce indentation (& D)
17_15 _ increase the indentation (& I)
17_333 _ insert table (& I )...
17_9 _ column (& C )...
17_3174 _ text box (& F)
17_204 _ plotting (& D)
17_17 _ chart (& H)
17_24 _ envelope (& E)
17_2566 _ spelling and syntax (& S )...
17_2521 _ print (& P)
17_5 _ single page (& O)
17_7_ratio 100% (& Z)
17_6 _ window (& F)
18_354 _ reply to the sender (& R)
18_355 _ all replies (& L)
18_356 _ forward (& W)
18_2521 _ print (& P)
18_19 _ copy (& C)
18_357 _ mobile mail (& M)
18_358 _ delete an email (& D)
18_359 _ Project (& I)
18_360_project (& I)
18_3271 _ auto format (& )...
18_340_highlight (& H)
18_1751 _ email header (& M)
18_1714 _ document structure (& D)
18_119 _ show all (& S)
18_1733 _ display ratio (& Z ):
18_984_microsoft word help (& H)
19_2188 _ email recipient (in the form of an attachment) (& )...
19_0000_select name (& N )...
19_361 _ Check name (& K)
19_2618 _ attributes (& P)
19_3 _ save (& S)
19_2521 _ print (& P)
19_2566 _ spelling and syntax (& S )...
19_21 _ Cut (& T)
19_19 _ copy (& C)
19_22 _ paste (& P)
19_108 _ format brush (& F)
19_128 _ unrecoverable (& U)
19_129 _ unrecoverable (& R)
19_1576 _ HYPERLINK (& I )...
19_777 _ file (& L )...
19_8 _ insert table (& I )...
19_3271 _ auto format (& )...
19_1751 _ email header (& M)
19_1714 _ document structure (& D)
19_119 _ show all (& S)
19_1733 _ display ratio (& Z ):
19_984_microsoft word help (& H)
20_340_highlight (& H)
20_2805 _ dot (& D)
20_714 _ double strikethrough (& D)
20_3511 _ pinyin Guide (& U )...
20_3512 _ merge characters (& C )...
20_3969 _ circled characters (& E )...
20_54 _ single-factor line spacing (& S)
20_55_1.5 times the line spacing (& 1)
20_56_2 times the line spacing (& D)
20_9 _ column (& C )...
21_205 _ Automatic Image Collection (& X )...
21_30423 _ Automatic Image Collection (&)
21_963 _ create (& N )...
22_1017 _ return (& B)
22_1018 _ forward (& F)
22_1019 _ stop current jump (& S)
22_1020_refresh the current page (& R)
22_1016_start page (& S)
22_1922 _ search Web (& W)
22_30176 _ favorites
22_30328 _ heading (& G)
22_1023 _ only display "Web" toolbar (& S)
22_1740 _ address (& ):
23_1031 _ wordart (& W )...
23_2094 _ edit text (& X )...
23_1606 _ art font library (& W)
23_3249 _ object (& O )...
23_1058 _ art word shape (& W)
23_688 _ free rotation (& T)
23_1404 _ Text wrap (& T)
23_1063 _ Same letter height (& W)
23_1061 _ vertical text (& W)
23_1059 _ art word alignment (& W)
23_1060_wordart Character spacing (& W)
24_1374 _ set/cancel 3D effect (& 3)
24_1375 _ lower bend (& T)
24_1376 _ upstreaming (& T)
24_1377 _ left (& T)
24_1378 _ Right (& T)
24_1379 _ depth (& D)
24_1380 _ direction (& D)
24_1382 _ lighting angle (& L)
24_1383 _ surface effect (& S)
24_1694 _ 3D Color (& 3)
25_2175 _ set/cancel shadow (& S)
25_1068 _ move up (& N)
25_1069 _ move down (& N)
25_1070 _ move left (& N)
25_1071 _ move right (& N)
25_1693 _ shadow color (& S)
26_2619 _ clip Library (& P )...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.