Word box for code

Code snippet in Word

If you’re creating an article, instructional piece, or essay in Microsoft Word, you may need to include a snippet of code. Whether HTML, JavaScript, or Python, you likely want it to appear different than the document text.

There are a few ways to insert command or code blocks in your Word document. Depending on if you want the reader to simply view the code or have the ability to copy it, let’s walk through the options.

Option 1: Paste Special as HTML

One of the quickest ways to add code to your document is with the Paste Special option for HTML. This inserts the code you’ve copied without the other formatting of your document. And, this option allows your reader to copy the code or command straight from your document.

RELATED: How to Paste Text Without Formatting Almost Anywhere

Select the code or command from your application and copy it using the toolbar, the context menu, or the keyboard shortcut Ctrl+C on Windows or Command+C on Mac.

Copy in the shortcut menu

Place your cursor in your Word document where you want to paste it. Then go to the Home tab, click the Paste drop-down arrow, and choose Paste Special. Select “HTML Format” and click “OK.”

HTML Format selected in the Paste Special box

When the code appears in your document, you can format the font or the snippet if you like.

Pasted HTML in Word

Use the Home tab to color specific pieces of code with the Font section of the ribbon. To add a border or shade, select the Borders drop-down arrow in the Paragraph section and pick “Borders and Shading.”

Shaded code block in Word

Option 2: Insert an Object

If you want to insert the code or command in your document only for the reader to see and not copy or edit, you can insert an object containing the snippet.

RELATED: How to Insert a Picture or Other Object in Microsoft Office

Go to the Insert tab, click the Object drop-down arrow, and pick “Object.”

Object on the Insert tab

On the Create New tab, select “OpenDocument Text” as the Object Type. Click “OK.”

OpenDocument Text selected in the Object box

A new Word document will open for you to insert your code or command. You can use the Paste Special HTML format described earlier if you like. After you add the snippet, close the document.

Your code then appears in your original Word document as an object. You can then move it, resize it, or add a border if you wish.

Object inserted in Word

Option 3: Attach a Screenshot

Another option for adding your snippet as an item instead of text is using an image. If you have your code or command in an active application window like Notepad++ or Command Prompt, you can easily add it to your document. The drawbacks here are that the reader can’t easily copy your code if they need to and that resizing may negatively affect readability.

Go to the Insert tab and click the Screenshot drop-down arrow. You should see the application window as an option.

Available windows in the image menu

Select it and it’ll pop into your document as an image. You can then crop the image to remove the surrounding application window if you like.

Inserted image in Word

Alternatively, you can use the Screen Clipping option in the Screenshot drop-down. When you select this tool, your cursor changes to a crosshair. Use it to drag the area of your screen or other application window you want to capture and release.

Screen Clipping tool capturing an image

That image then appears in your document. You can move, resize, or customize the snippet screenshot like any other image in Word.

Screen Clipping inserted in Word

Option 4: Use a Syntax Highlighter

One more option is to use a syntax highlighter like Easy Syntax Highlighter. This is a free add-in for Microsoft Word that highlights your code for you including a background and colors for pieces of the code. Plus, you can customize the language and appearance.

RELATED: How to Install and Use Add-ins for Microsoft Office

After you install the add-in, place the code or command in your document. You can type or paste it, whichever you prefer.

Select the code and go to the Easy Syntax Highlighter tab that now displays. To apply the default formatting with the language automatically detected, select “Highlight Selection” in the ribbon.

Highlight Selection on the Easy Syntax Highlighter tab

You’ll see your snippet highlighted and your text formatted.

Snippet highlighted with default theme

If you want to select a specific language or formatting, select “Settings” in the ribbon instead. When the sidebar opens, choose a Language and Theme.

Language and Theme in the Settings

With your code selected, click “Highlight Selection” in the sidebar.

Highlight Selection in the sidebar

You’ll then see your snippet formatted per the settings you picked. This keeps your code or command as text so your reader can copy it, but makes it stand out as its own block.

Snippet highlighted with dark theme

There’s more than one way to add a code or command block to your Word document. Depending on the purpose for your reader, choose the option that’s best for you!

READ NEXT

  • › Microsoft Outlook Is Adding a Splash of Personalization
  • › Why Your Phone Charging Cable Needs a USB Condom
  • › Five Types of Phone Damage That Aren’t Covered by Your Free Warranty
  • › This 64 GB Flash Drive From Samsung Is Just $8 Right Now
  • › The Best Steam Deck Docks of 2023
  • › Spotify Is Shutting Down Its Free Online Game

I’m trying to format some text in my Word doc to have a background color of gray. This is for me to have a Quick Style to apply this formatting. I want to use a monospaced font, like Consolas, and have the entire block have a gray background. When I highlight text and set the background color though, it only set the color behind the text, not the area rectangular area the text sits on within the doc layout. How can I do this?

asked May 2, 2012 at 20:28

Mark's user avatar

MarkMark

9206 gold badges18 silver badges28 bronze badges

3

I’ve figured out how to do this:

  1. Highlight arbitrary text in the document
  2. In the Styles chunk of the ribbon, Save Selection as new Quick Style…
  3. In the Modify Style dialog, click Format at the bottom.
  4. Select Frame
  5. Set Text Wrapping to Around
  6. Click OK, then in the Format menu select Border
  7. In the Shading tab, pick a Fill with the background color, e.g. gray

answered May 3, 2012 at 14:02

Mark's user avatar

MarkMark

9206 gold badges18 silver badges28 bronze badges

For Office 2007 and 2010, you’ll want to use the Shading tool:

enter image description here

That should do what you want.

I don’t have an older version of Office handy to check, but you’ll probably find the same tool under Format -> Paragraph, or similar menu option.

answered May 2, 2012 at 20:55

Indrek's user avatar

IndrekIndrek

24k14 gold badges89 silver badges93 bronze badges

2

I have found a simpler way to do this. Step by step:

  1. Copy the code which you want to paste into a Word document.
  2. Open the link http://hilite.me
  3. Paste your code into the left side box and select the appropriate
    language from the drop-down menu. Then click the “highlight” button.
  4. Copy your code from the preview section and open your Word document.
  5. Insert a table of 1×1 size and paste your code there. 
    Style it according to your choice.

If something is still unclear, please have a look at this YouTube video.

G-Man Says 'Reinstate Monica''s user avatar

answered Aug 30, 2019 at 6:49

Vikash kumar Yadav's user avatar

From Office 2013 there is a new quick style called ‘Code’. You can disable spell-check by

Format->Language->Disable automatic spell-checking.

answered Feb 24, 2014 at 13:47

Rakesh's user avatar

RakeshRakesh

6108 silver badges12 bronze badges

1

Select the block where you want to fill the background with color, on the home section of microsoft word, above paragraph, the section where you will find the bullets & numbering there is a bucket like paint icon called the shading click the down arrow next to that icon and select any color you want to use for the background then voila!

answered May 7, 2012 at 10:49

Dima's user avatar

DimaDima

1965 bronze badges

I had been preparing a flashcard to learn English for a long time. To do these things faster, I made an application with react native and did not publish it anywhere. The project is not fully finished. But you can add and use words. So I wanted to put it up to this stage. If you want, you can continue developing.

github: https://github.com/berat/wordBox-react-native

Demo (Video)

Screenshot



Thank you for your watching

To follow me Github — Twitter — Linkedin

Top comments (0)

Word Box

A vocabulary builder, to help learn a new language.
The app will maintain a list of words known to the user and, when a new piece of text is pasted in, the app will highlight known words in green and new words in red. You can save these texts (currently in local storage).

There is also a tab where you can look through the known words and click them to see a translation. And finally: there is a test page where the computer will generate random sentences from the words it knows and ask you for the translation.

Please note: while there is no wish to recreate Monty’s Hungarian phrase book, I don’t speak Czech that well. I have been as accurate as I can. The grammar may come up wrong, especially as we aim for harder sentences.

Made by

geckos-team-09, on Chingu’s voyage 9

Team members: TomMac and Samir70

Technology

HTML, CSS, React (via Create React App), React Bootstrap and JavaScript

(eventually) we will need some way to save data someplace other than local storage.There is no database or backend, though we plan to look at this in the future.

Deploying your own Word Box

This version is currently hosted on github, via gh-pages.
If you want to deploy one of your own, you can:

  • fork this repo
  • open a command line and change to a directory with the repo name
  • clone your fork of the repo
  • type this on the command line to install all the dependencies:

npm install

(In case you don’t know: you have to have installed node for that to work)

  • then, to use the App from your local copy:

npm start

Make changes, push them to your repo and keep in touch. We would especially like help getting a backend to this project, so that the user can save new words. Or even switch languages.

Adding words to vocab.js

The wordList object has several properties.

foreignLang

This allows the app to use the name of the language in the placeholder for the answer sentence. And in the modals which provide the translations in the known words tab when a word is clicked.

defArticle

This itself has the properties of male, female, neuter. If one or more of these is undefined, the modal will display — for it. It also has the property of wordType, which returns ‘definite article’.

nouns

Make a noun object for the word ‘beer’:

var beer = new Noun(‘beer’);

beer.foreign = ‘pivo’;

beer.gender = ‘neuter’;

Provide the english when first creating your noun. It is then accessed with

beer.english //returns the string ‘beer’

The word then also gets the property:

beer.wordType // returns ‘noun’

Gender needs to be: ‘male’, ‘female’ or ‘neuter’.

Though Czech, and other languages, use noun cases (such as nominative and accusative) this has not been implemented yet.

verbs

These have the wordType ‘verb’.

Currently: only the present tense is defined in vocab. Example definition:

var toBe = new Verb(‘to be’);

toBe.infinitive = ‘byt’;

toBe.present = [‘am’, ‘are’, ‘is’, ‘are’, ‘are’, ‘are’];

toBe.presentForeign = [‘jsem’, ‘jsi’, ‘je’, ‘jsme’, ‘jste’, ‘jsou’];

The getter toBe.present also returns an array. Adjectives do not behave this way.

adjectives

The setter for the translation of an adjective requires an array, of up to 3 elements. If the array is smaller, then the later genders will be undefined and appear as — in the modal. The setter creates an object with properties: male, female and neuter. Example:

var blue = new Adjective(‘blue’);

blue.foreign = [‘modry’, ‘modra’, ‘modre’];

And the data is retrieved via:

blue.english //returns ‘blue’

blue.foreign.neuter // returns ‘modre’

Using Word-Box

Starting on the ‘New Text’ tab, you can paste some text and click save. If you don’t give a title, saving will create a default title from your text.
Some edited text

Then click on ‘study’ and Word-Box will analyse your text:
Analysed text

The green words are the ones Word-Box has recognised. ‘pampeliska’ is mis-spelt, so appears red — like the other words which are not recognised.

Currently: your text is saved in local storage, so should be accessable when you return to the page. (But not all browsers allow this). You can see your catalogue on the ‘My Texts’ tab.

My Words tab

You can search for words here by looking through the alphabetical list or typing in the search box. If you want to see the translation of a word: click on it in the list. Verbs are conjugated, and all gender forms of adjectives are given.

If you search for a word that isn’t known by Word-Box, you will get a link to an online dictionary.

Test tab

Word-Box will use its vocab to make up a sentence. (Apologies for any rudeness: None of the words I have put into the vocab are individually rude. But the combinations come up at random and Word-Box knows not the meaning of what it says).

Type your answer where prompted. Each word is compared to the translation Word-Box has in mind. Obviously: there are many ways to say the same thing. But Word-Box is only thinking of one of these. Words get marked according to their position and spelling (case-insensitive). eg:
cold hospital translation

‘nemocnice’ is correctly spelled and should be the second word. And so it is marked green. Why are some words marked red? (hint: what gender is a hospital?)

If you don’t know how to translate the sentence: there is a hack! Click the ‘Translate the other way’ button. This swaps question and answer. You will now be given the same sentence in Czech, and be asked for the English translation. You can copy and paste, but you will learn more slowly if you do! (Teacher voice: ‘You’re only cheating yourself!’). Once you’ve read the answer, click the button again and type in the translation.

Word-Box will toast every correct answer and keep count of your successes, but this count is reset every time you restart.

You can also use SciTE to paste code if you don’t want to install heavy IDEs and then download plugins for all the code you’re making. Simply choose your language from the language menu, type your code, high-light code, select Edit->Copy as RTF, paste into Word with formatting (default paste).

SciTE supports the following languages but probably has support for others: Abaqus*, Ada, ANS.1 MIB definition files*, APDL, Assembler (NASM, MASM), Asymptote*, AutoIt*, Avenue*, Batch files (MS-DOS), Baan*, Bash*, BlitzBasic*, Bullant*, C/C++/C#, Clarion, cmake*, conf (Apache), CSound, CSS*, D, diff files*, E-Script*, Eiffel*, Erlang*, Flagship (Clipper / XBase), Flash (ActionScript), Fortran*, Forth*, GAP*, Gettext, Haskell, HTML*, HTML with embedded JavaScript, VBScript, PHP and ASP*, Gui4Cli*, IDL — both MSIDL and XPIDL*, INI, properties* and similar, InnoSetup*, Java*, JavaScript*, LISP*, LOT*, Lout*, Lua*, Make, Matlab*, Metapost*, MMIXAL, MSSQL, nnCron, NSIS*, Objective Caml*, Opal, Octave*, Pascal/Delphi*, Perl, most of it except for some ambiguous cases*, PL/M*, Progress*, PostScript*, POV-Ray*, PowerBasic*, PowerShell*, PureBasic*, Python*, R*, Rebol*, Ruby*, Scheme*, scriptol*, Specman E*, Spice, Smalltalk, SQL and PLSQL, TADS3*, TeX and LaTeX, Tcl/Tk*, VB and VBScript*, Verilog*, VHDL*, XML*, YAML*.

Понравилась статья? Поделить с друзьями:
  • Word box achievement adventure
  • Word boundary is not
  • Word boundaries что это такое
  • Word boundaries in speech
  • Word boundaries in sentences