I would like to be able to provide code snippets in a Microsoft Word document and retain the syntax coloring from Textpad (version 5.03). Anyone have a convenient method for doing this?
emeier
retaining Textpad syntax coloring in Microsoft Word
Moderators: AmigoJack, bbadmin, helios, MudGuard
Easiest way I can think of is to press "print screen" to copy the screen image to clipboard, use MS-Paint to crop what you want, select what is left and paste into word.
This fine if your code fits on one screen when you capture the screen to clipboard.
Or just past the text into Word and use Word's tools to colour it.
This fine if your code fits on one screen when you capture the screen to clipboard.
Or just past the text into Word and use Word's tools to colour it.
-
bveldkamp
This is something I've wanted to be able to do easily for a long time. I commonly copy code fragments and paste them into e-mail messages or word documents, and it would be very nice to retain the syntax coloring.
Images take up too much space, and it takes too many steps to use Copy Other -> as HTML Page.
I've determined a way to automate most of the steps using a TextPad Macro and an external script, but I cannot determine any way to get a Macro to invoke an external script or executable.
Following are the steps necessary:
0. Starting point: text to copy is selected in Textpad
1. Copy Other -> As HTML Page
2. File -> New
3. Edit -> Paste (in new document)
4. File -> Save As...
5. enter "%temp%\Document1.html" for filename and select Save, then Overwrite.
(Steps 1-5 can be done as a TextPad Macro)
6. Open "%temp%\Document1.html" in Internet Explorer
7. Edit -> Select All
8. Edit -> Copy
(Steps 6-8 can be done in VB using the Microsoft Internet Controls library - Shdocvw.dll)
I'm looking for a way to connect all of this into one step, but I seem to be lacking a way to get a Macro to invoke an external script or program. If there is a way to do that, please let me know.
Thanks,
BaryH
Images take up too much space, and it takes too many steps to use Copy Other -> as HTML Page.
I've determined a way to automate most of the steps using a TextPad Macro and an external script, but I cannot determine any way to get a Macro to invoke an external script or executable.
Following are the steps necessary:
0. Starting point: text to copy is selected in Textpad
1. Copy Other -> As HTML Page
2. File -> New
3. Edit -> Paste (in new document)
4. File -> Save As...
5. enter "%temp%\Document1.html" for filename and select Save, then Overwrite.
(Steps 1-5 can be done as a TextPad Macro)
6. Open "%temp%\Document1.html" in Internet Explorer
7. Edit -> Select All
8. Edit -> Copy
(Steps 6-8 can be done in VB using the Microsoft Internet Controls library - Shdocvw.dll)
I'm looking for a way to connect all of this into one step, but I seem to be lacking a way to get a Macro to invoke an external script or program. If there is a way to do that, please let me know.
Thanks,
BaryH
Two Step Solution
I haven't been able to determine how to do this in one just one action, but I have a solution that can be done in two steps.
I realized that steps 2 - 8 from the previous post can all be done in VB, so that eliminates the need for a TextPad macro at all.
Following is the VB6 code to do this:
This can be compiled into an executable, and then configured as an External Tool in TextPad.
Then you can assign a shorcut key to it. For example, you could assign Cntl+1 to EditCopyAsHTML and then Cntl+2 to this external tool. Thus, with two quick keystrokes, you have something ready to paste into Word or e-mail that retains the syntax coloring.
Note: I wanted to do this in VBScript which would be easier to distribute, but I could not get the ExecWB statements to work.
BaryH
I realized that steps 2 - 8 from the previous post can all be done in VB, so that eliminates the need for a TextPad macro at all.
Following is the VB6 code to do this:
Code: Select all
Public Sub Main()
Dim oFS As FileSystemObject
Dim oFile As TextStream
Dim tmpFileName As String, textAsHTML As String
'Grab the text from the System Clipboard
textAsHTML = Clipboard.GetText
'Put the temporary file in the user's TEMP directory
tmpFileName = Environ("TEMP") & "\Document1.html"
Set oFS = CreateObject("Scripting.FileSystemObject")
'Create the file (Overwrite = True), write the text from the Clipboard, and Close
Set oFile = oFS.CreateTextFile(tmpFileName, True)
oFile.Write textAsHTML
oFile.Close
Dim oIE As InternetExplorer
Set oIE = CreateObject("InternetExplorer.Application")
'Open the temporary file in the browser
oIE.Navigate (tmpFileName)
' Ensure the browser is ready
Do While oIE.Busy
Loop
' Do Select All, then Copy Commands in browser
oIE.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT
oIE.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT
oIE.Quit
'One can delete the temporary file here, if desired.
'oFS.DeleteFile tmpFileName
End Sub
Then you can assign a shorcut key to it. For example, you could assign Cntl+1 to EditCopyAsHTML and then Cntl+2 to this external tool. Thus, with two quick keystrokes, you have something ready to paste into Word or e-mail that retains the syntax coloring.
Note: I wanted to do this in VBScript which would be easier to distribute, but I could not get the ExecWB statements to work.
BaryH