Microsoft Word Insert Code Snippets

  1. See Full List On Owlcation.com
  2. Microsoft Word For Mac Insert Code Snippet
  3. How To Insert Source Code Into A Word Document

Code snippets can be accessed in the following general ways: On the menu bar, choose Edit IntelliSense Insert Snippet. From the right-click or context menu in the code editor, choose Snippet Insert Snippet. From the keyboard, press Ctrl + K, Ctrl + X. Note of mine (after checking this solution), just to clear: After inserting the object Word will open a new instance, which is the code snippet. Just paste the code, save and close. If you will want to edit the code just double-click the snippet and Word will open the document. Microsoft offers a wide variety of Word templates for free and premium Word templates for subscribers of Microsoft 365. Whether you're planning a holiday party, in charge of the school newsletter, or want a matching resume and cover letter combination, you can find templates for Word that fit your needs. Oct 02, 2015 Open MS Word and place the cursor where you want to paste the snippet. Go to the Insert tab, from there click to the Object button close to the right-end of the toolbar. A popup will show up: select OpenDocument Text. This process has two steps. First you create an AutoText snippet and then you assign the snippet a keyboard shortcut. Create an AutoText snippet 1. Set up and format the text you want to template. Highlight the text, then click on Insert ⇒ Quick Parts ⇒ AutoText ⇒ Save Selection to AutoText Gallery. Assign the selection a title.

Many users want to be able to make small screen tips in Word that work like the screen tips known from Websites, i.e. small boxes with information that appear when you hover the mouse over a text like here. For example, such screen tips may be used to show definitions of terms. Word has no functionality specifically for that but you can make use of the hyperlink functionality and obtain something similar.

See Full List On Owlcation.com

You can create such 'screen tips hyperlinks' manually. However, this includes a number of steps: You must select text, add a bookmark with an appropriate name, create a hyperlink and enter the screen tip text, and format the text.

Here you will find a set of macros that automate the process. One macro lets you add screen tips hyperlinks in a structured way and another one lets you easily remove a screen tip hyperlink again if you wish.

Instead of installing the macro solution available on this page you may be interested in the ready-to-use add-in DocTools ScreenTipManager. You will find an introduction and a link to that add-in below.

Quick Navigation

DocTools ScreenTipManager - advanced add-in for Word

DocTools ScreenTipManager makes it fast and easy to create and edit screen tips in Word with up to 2040 characters.

Screen tips you create using the free macro solution on this page are limited to 255 characters. The add-in also includes many other features.

The add-in works with Microsoft Word 2010 and newer versions on PC/Windows.

You can access the functionality of the add-in from a custom tab in the Ribbon.

How to get the DocTools ScreenTipManager add-in

This advanced add-in is not free but the return on investment is almost immediate. It will make all your future work with screen tips fast and easy.

Click the button below to learn more about DocTools ScreenTipManager or to buy the add-in.

You can try DocTools ScreenTipManager risk-free for 7 days.

Macro solution

Read below if you want to use the macro instead of the add-in.

How the screen tips macros work

The macro module you can download via the link below contains three macros:

Microsoft Word Insert Code Snippets
  • AddScreenTipToText
  • GetBookmarName (used by the macro above)
  • RemoveScreenTipFromText
Word

For easy access, you can assign keyboard shortcuts to the macros. Alternatively, you can assign the macros to a toolbar (Word 2003 and earlier versions) or the Quick Access Toolbar (QAT) (Word 2007 and later versions).

To add a screen tip hyperlink, select the relevant text, run the macro AddScreenTipToText. In the dialog box that opens, enter the text you want to appear in the screen tip. Click OK.

The text you entered will now appear in a screen tip when a user hovers the mouse over the text. Shading will be applied to the hyperlinked text in order to make it easy for the user to identify text with screen tips. The normal Hyperlink style will automatically be removed from the hyperlink so that the user can distinguish screen tip hyperlinks from ordinary hyperlinks. You can change the shading color in the macro if you wish.

If you wish to break your screen tip text into multiple lines, follow the instructions in the dialog box. In the example illustrated below, a screen tip with two lines of text is created.

To remove a screen tip, select the screen tip hyperlink or just click in it. Then run the macro RemoveScreenTipFromText.

Note that the screen tip text cannot exceed 255 characters.

For further details about how the macros work, please refer to the comments in the macros.

The illustration below shows the dialog box in which you specify the screen tip text. A sample text has been inserted:

The illustration below shows how screen tips hyperlinks will appear in the document. The displayed screen tip contains the text entered in the dialog box illustrated above:

Additional hints about how the screen tips work

You do not need to read the following in order to use the macros. However, it may help you understand how it works.

You only need the macros in order to add/remove screen tips hyperlinks. No macros need to be available to the end user of the document. This means that you can store the macros e.g. in your Normal.dot/Normla.dotm or in a global template placed in your Word Startup folder.

Since the screen tips are actually made as hyperlinks, you will find the standard hyperlink text Ctrl + click to follow link or Click to follow link at the bottom of the screen tips. That text cannot be removed. Whether Ctrl + click or only Ctrl is shown depends on whether or not the option Use Ctrl + click to follow hyperlink is turned on – here shown as it appears in Word 2003; in Word 2007 and 2010 you will find the option in the Word Options dialog, below the Advanced category:

The Word option for displaying screen tips must be turned on. In Word 2003, you will find the option here:
Tools > Options > View tab > Show group > Screen Tips.

In Word 2007 you will find the option here:
Office button > Word Options > Display category > Show document tooltips on hover.

In Word 2010, Word 2013 and Word 2016, you will find the option here:
File > Options > Display category > Show document tooltips on hover.

Note the screen tips are automatically turned on by the AddScreenTipToText macro. If the screen tips do not appear on a user's PC, ask the user to turn on the option on his/her PC.

In order to make the selection remain unchanged if a user Ctrl+clicks or clicks the hyperlink, a bookmark is added around the hyperlink itself and the hyperlink is defined to go to that bookmark, i.e. the cursor does not jump to another place.

Hyperlinks are fields. A field contains field code, i.e. instructions to Word about what to do. You can display the field codes by pressing Alt+F9. If you display field codes, you will see that the screen tips hyperlinks look as illustrated below. Note that formatting marks are shown so that you can se both the paragraph mark in the two-line screen tip and the spaces in the field code:

Microsoft Word For Mac Insert Code Snippet

The field consists of these parts:

  • HYPERLINK is the field type
  • l tells Word to go to the bookmark named '_ScreenTip_4'
  • o tells Word to display the text that follows as screen tip text
Microsoft Word Insert Code Snippets

Note that all the bookmarks created by the AddScreenTipToText macro are named '_SrceenTip_X' where X is a number. Bookmarks that start with an underscore are treated as hidden. If you open the Bookmark dialog box, you need to turn on Hidden bookmarks to see the bookmarks in the list. You cannot manually create hidden bookmarks. They can only be added programmatically. It you do not want the bookmarks to be hidden, you must change the macro code.

If you copy a screen tip hyperlink to another place in the same document, the copy points to the bookmark in the original screen tip since the bookmark name in the field code has not been changed. Thus, if a user clicks such copied screen tip hyperlink, the cursor will now jump to the original screen tip. The easiest way to correct this may be to remove the copied screen tip hyperlink using the RemoveScreenTipFromText macro and then create a new one using the AddScreenTipToText macro. The AddScreenTipToText macro always creates a uniquely named bookmark in the correct place.

Screen tips hyperlinks can only be seen in the Word document. For example, they will not appear if you create a PDF file.

The macros

Below, you will find the macro code. If you need help on installing macros, see How to install a macro.

Related information

See About VBA Macros and Code Snippets and How to Install a Macro for misc. information that may help you in your work with macros and for information about how to install macros.

How often were you required to paste some sort of source code into a word document and realized that how difficult it is to keep the correct formatting and indentation?

Well there are a lot of ways you could use to achieve the desired output. However, there is a simple way to achieve this which works for me always. So here’s the trick.

The Steps

Insert

How To Insert Source Code Into A Word Document

  • Step 1:

    Here’s some sample C# code written in Visual Studio 2012. I want to paste this code block into a word document.

  • Step 2:

    Here’s the word document that I want to paste my formatted code.

  • Step 3:

    Place your cursor at the point where you want to place your code. Select the “INSERT” tab on the ribbon and click on the “Insert Object” icon.

  • Step 4:

    The “Object” dialog box will appear. From the “Create New” tab of the dialog box, select the “OpenDocument Text” option and click “OK”.

  • Step 5:

    A new word document will open. Paste your code in this new document. Save and close the document.

  • Step 6:

    Your original document will look as below. If you want, you can double click on the object and edit the code again. Once done, you just need to save the document and it will update the code within your document.

  • Step 7:

    As a last and optional step, you might want to fix the layout of the object to wrap with the text. To do this, right click on the object and select “Format Object”. The “Format Object” dialog box appears. Click on the “Layout” tab and select the wrapping style as “In line with text”. Your final code will look as below.