---
title: "Pasting nicely formatted code into your blog"
url: "https://osherove.com/blog/2004/2/5/pasting-nicely-formatted-code-into-your-blog.md"
canonical: "https://osherove.com/blog/2004/2/5/pasting-nicely-formatted-code-into-your-blog.html"
published: "2004-02-05T10:08:00"
updated: "2004-02-05T10:08:00"
tags: ["Blogging"]
author: "Roy Osherove"
description: "BTW, I was asked how I put the code so nicely formatted on my blog. Here are the steps: Write the code in vs.net Paste it into a new word document Save the document as an html(filtered) (or .Text will have trouble with…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Pasting nicely formatted code into your blog

By Roy Osherove February 5, 2004 In [Blogging](https://osherove.com/blog/category/blogging)

**Historical article** · Originally published February 5, 2004; technical details may be outdated.

BTW, I was asked how I put the code so nicely formatted on my blog. Here are the steps:

- Write the code in vs.net
- Paste it into a new word document
- Save the document as an html(filtered) (or .Text will have trouble with it)
- Close the doc , then re-open it without changing any text after that (this is an important step)
- Copy the code from the doc into your blog post

**Update**: ok. This was just too obvious. I've created a short word macro that does this for you.

simply paste the following code in a new macro module in word that belongs to the Normal.dot template.

Then assign it a keyboard shortcut using right click on toolbars-customize-keyboard-macros and you're done:

Sub FormatCodeForBlog()

    Selection.PasteAndFormat(wdPasteDefault)

    ActiveDocument.SaveAs(FileName:="temp.htm", FileFormat:=wdFormatFilteredHTML, \_

          LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword \_

        :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, \_

        SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= \_

        False)

    ActiveWindow.View.Type = wdWebView

    ActiveWindow.Close()

    RecentFiles(1).Open()

    Selection.WholeStory()

    Selection.Copy()

End Sub

## More in Blogging

[All posts in Blogging](https://osherove.com/blog/category/blogging)

- Feb 15, 2004

    ### ["How do I open a weblog here?"](https://osherove.com/blog/2004/2/15/quothow-do-i-open-a-weblog-herequot.html)

- Feb 5, 2004

    ### [.Net Rocks live - review](https://osherove.com/blog/2004/2/5/net-rocks-live-review.html)

- Jan 26, 2004

    ### [Some new blogs and a story of quantity vs. quality](https://osherove.com/blog/2004/1/26/some-new-blogs-and-a-story-of-quantity-vs-quality.html)

- Jan 25, 2004

    ### [School Blogging](https://osherove.com/blog/2004/1/25/school-blogging.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
