I'm coming in to this discussion well after it had ended, but I wanted to make a note here that might someday be helpful to someone........
.......Me too!......
Hi, I also hit a problem. And often I hit this Thread on a search trying to solve it....so I thought i would share my solution ( or workaround )
_....................................
Just brief details: When Pasting into a Thread Editor ( a code to a HTML ( or php) Window in this case )
sometimes carriage Returns seem to “vanish” in the final Posted Post.
It has caught me out a few times when pasting codes.
_...................
Anyway, a workaround:....
My “Theory” to it ( probably as naively wrong as all of them.. ) ... back in the early days... a carriage return brought the Printer back to the start at the left
But then you needed also ...
A Line feed to go to the next line to be printed on.
Somewhere along the line the exact translation to what similarly happens in a modern computer world is a bit abstract. So a carriage return ( or Line feed alone ) might work. But maybe doing a carriage return and a Line feed would not do any harm and might occasionally help....
Ties up a bit may be with what amulee said in Post #4
https://en.wikipedia.org/wiki/Teleprinter
_....................................
So Try this: After copying to the clipboard from the code Window, run this code ( From Word or Excel )
Code:
[color=darkgreen]' http://www.eileenslounge.com/viewtopic.php?f=26&t=22603&start=20#p176255 http://www.excelfox.com/forum/f13/bbcode-table-2077/#post9687 ( Manual Solution Alternative: http://www.excelfox.com/forum/f13/bbcode-table-2077/#post9645 )[/color]
[color=blue]Sub[/color] PutInAvbLfInClipboadText() [color=darkgreen]' "Replcace vbCr with vbCr & vbLf "[/color]
[color=darkgreen]'Get Current Text from Clipboard[/color]
[color=blue]Dim[/color] objDat [color=blue]As[/color] DataObject
[color=blue]Set[/color] objDat = [color=blue]New[/color] DataObject [color=darkgreen]'Set to a new Instance ( Blue Print ) of dataobject[/color]
[color=darkgreen]'Dim obj As Object[/color]
[color=darkgreen]'Set obj = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")[/color]
objDat.GetFromClipboard [color=darkgreen]'All that is in the Clipboard goes in this Data Object instance of the Class.[/color]
[color=blue]Let[/color] TxtOut = objDat.GetText() [color=darkgreen]'retrieve the text in this instance of the Class. ( In this case all I have in it is the text typically I think as it is coming from a Ctrl C Copy from the VB Editor )[/color]
[color=blue]Dim[/color] originalClipboardText [color=blue]As[/color] String: [color=blue]Let[/color] originalClipboardText = TxtOut
[color=blue]Dim[/color] TextWithExtravbLF [color=blue]As[/color] [color=blue]String[/color]
[color=blue]Let[/color] TextWithExtravbLF = Replace(TxtOut, vbCr, vbCr & vbLf, 1, -1) [color=darkgreen]'Replace ( in TxtOut , vbCr , with vbCr & vbLf , start looking at AND/OR Only consider and FINALLY OUTPUT from character 1 ( so all in this case ), -1 means look at and change all occurrances )[/color]
[color=darkgreen]'Dump in Clipboard: This second instance of Data Object used to put in Clipboard[/color]
[color=blue]Dim[/color] objCliS [color=blue]As[/color] DataObject [color=darkgreen]'**Early Binding. This is for an Object from the class MS Forms. This will be a Data Object of what we "send" to the Clipboard. So I name it CLIpboardSend. But it is a DataObject. It has the Methods I need to send text to the Clipboard[/color]
[color=blue]Set[/color] objCliS = [color=blue]New[/color] DataObject [color=darkgreen]'**Must enable Forms Library: In VB Editor do this: Tools -- References - scroll down to Microsoft Forms 2.0 Object Library -- put checkmark in. Note if you cannot find it try OR IF NOT THERE..you can add that manually: VBA Editor -- Tools -- References -- Browse -- and find FM20.DLL file under C:\WINDOWS\system32 and select it --> Open --> OK.[/color]
[color=darkgreen]' ( or instead of those two lines Dim obj As New DataObject ). or next two lines are.....Late Binding equivalent'[/color]
[color=darkgreen]'Dim obj As Object' Late Binding equivalent' If you declare a variable as Object, you are late binding it. http://excelmatters.com/2013/09/23/vba-references-and-early-binding-vs-late-binding/[/color]
[color=darkgreen]'Set obj = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")' http://excelmatters.com/2013/10/04/late-bound-msforms-dataobject/[/color]
objCliS.SetText TextWithExtravbLF [color=darkgreen]'Make Data object's text equal to a copy of ORefiginalText[/color]
objCliS.PutInClipboard [color=darkgreen]'Place current Data object into the Clipboard[/color]
[color=darkgreen]' Get from clipboard. This a Another Object from class to be sure we have the data in the Clipboard[/color]
MsgBox prompt:="You dumped in Clipboard originally this " & vbCr & TxtOut & vbCr & "and if you try to get it, you should get" & vbCr & TextWithExtravbLF & ""
[color=darkgreen]' End clean up.[/color]
[color=darkgreen]'TheEnd: ' ( Come here always, even on a unpredictable error )[/color]
[color=blue]Set[/color] objDat = [color=blue]Nothing[/color] [color=darkgreen]' Good practice... maybe....[/color]
[color=blue]Set[/color] objCliS = [color=blue]Nothing[/color] [color=darkgreen]' ....... http://www.mrexcel.com/forum/excel-questions/361246-vbnullstring.html#post4414065[/color]
[color=blue]End[/color] [color=blue]Sub[/color]
_.....
That above code simply replaces all
vbCr ‘s
With a
vbCr & vbLf
( So replaces a carriage return with a carriage return and a Line feed )
I am not sure of exactly what is going on. Either I am giving an extra carriage return to be “eaten” by the Forum editor, but maybe that does not tie up with further editing remaining stable . More likely it wants to see a vbLF to interpret the thing correctly. Just an idea from a computer Novice.
But anyway the workaround seems to work.
Worth a try if you are experiencing similar problems. And or experiment with a vbCrLf etc. etc.
( and post back and share if you notice anything different
)
Alan
One Final Note. This workaround does not always seem to be necessary. Different Forum editor, and changes from time to time to the software there of, can influence the results.....
Ref:
Eileen's Lounge • View topic - Word VBA Replace multiple Spaces in Text with BB Code String
P.s. i also have a “manual” solution ( Workaround 1) that seems to work but is a bit more tedious...
BBCode Table
_........................................................................................