Hi
This Code in a HTML ( or PHP ) Window still catches me out ( due to the “vanishing Carriage return problem ) , sometimes, so I am just checking ( using my Workaround 2 ), on a Code I noticed that seems to have the problem....
So I copy that code from Joe4 in Post #2
Test
to a VB Editor Window ( and put it in HTML Code Tags ), as that might be my normal “starting point” ( I just present a part for clarity here, but initially I did the experiment on the whole code and the important results were the same)
I post it into the Editor. It looks Ok initially In the Editor.....
[HTML]
Sub MyMacro()
Dim myRow As Long
Dim myLastRow As Long
Dim myCounter As Long
Dim mySplit As Long
Dim myNewRow As Long
Dim myInsert As Long
Dim myColA As String
Dim myColB As String
Dim myColC As String
Dim myColD As String
Dim myColE As String
' Find last row
[/HTML]
_................................................. ..........................
But then comes out like this in the final Post.
_................................................. ......................HTML Code:Sub MyMacro() Dim myRow As Long Dim myLastRow As Long Dim myCounter As Long Dim mySplit As Long Dim myNewRow As Long Dim myInsert As Long Dim myColA As String Dim myColB As String Dim myColC As String Dim myColD As String Dim myColE As String ' Find last rowEnd Sub
If I then relook in the editor ( by editing the post ) it no longer looks OK:
[HTML]Sub MyMacro()
Dim myRow As Long Dim myLastRow As Long Dim myCounter As Long Dim mySplit As Long Dim myNewRow As Long Dim myInsert As Long Dim myColA As String Dim myColB As String Dim myColC As String Dim myColD As String Dim myColE As String ' Find last row
End Sub[/HTML]
_...
Weird!!!!!!!!
_..............
My “Theory” ( 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...
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 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....
_....................................
So Try this: After copying to the clipboard from the code Window I run this code
_.....Code:' 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 ) Sub PutInAvbLfInClipboadText() ' "Replcace vbCr with vbCr & vbLf " 'Get Current Text from Clipboard Dim objDat As dataobject Set objDat = New dataobject 'Set to a new Instance ( Blue Print ) of dataobject 'Dim obj As Object 'Set obj = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") objDat.GetFromClipboard 'All that is in the Clipboard goes in this Data Object instance of the Class. Let TxtOut = objDat.GetText() '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 ) Dim originalClipboardText As String: Let originalClipboardText = TxtOut Dim TextWithExtravbLF As String Let TextWithExtravbLF = Replace(TxtOut, vbCr, vbCr & vbLf, 1, -1) 'Dump in Clipboard: This second instance of Data Object used to put in Clipboard Dim objCliS As dataobject '**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 Set objCliS = New dataobject '**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. ' ( or instead of those two lines Dim obj As New DataObject ). or next two lines are.....Late Binding equivalent' '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/ 'Set obj = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")' http://excelmatters.com/2013/10/04/late-bound-msforms-dataobject/ objCliS.SetText TextWithExtravbLF 'Make Data object's text equal to a copy of ORefiginalText objCliS.PutInClipboard 'Place current Data object into the Clipboard ' Get from clipboard. This a Another Object from class to be sure we have the data in the Clipboard MsgBox prompt:="You dumped in Clipboard originally this " & vbCr & TxtOut & vbCr & "and if you try to get it, you should get" & vbCr & TextWithExtravbLF & "" ' End clean up. 'TheEnd: ' ( Come here always, even on a unpredictable error ) Set objDat = Nothing ' Good practice... maybe.... Set objCliS = Nothing ' ....... http://www.mrexcel.com/forum/excel-questions/361246-vbnullstring.html#post4414065 End Sub
That code simply replaces all
vbCr 's
with a
vbCr & vbLf ( So replaces a carriage return with a carriage return and a Line feed )
Then in the editor initially I get this
[html]
Sub MyMacro()
Dim myRow As Long
Dim myLastRow As Long
Dim myCounter As Long
Dim mySplit As Long
Dim myNewRow As Long
Dim myInsert As Long
Dim myColA As String
Dim myColB As String
Dim myColC As String
Dim myColD As String
Dim myColE As String
' Find last row
End Sub
[/html]
_..........
In the post it now comes out OK:
_....HTML Code:Sub MyMacro() Dim myRow As Long Dim myLastRow As Long Dim myCounter As Long Dim mySplit As Long Dim myNewRow As Long Dim myInsert As Long Dim myColA As String Dim myColB As String Dim myColC As String Dim myColD As String Dim myColE As String ' Find last row End Sub
But note if i look again in the Editor by editing the post I see this:
[html]Sub MyMacro()
Dim myRow As Long
Dim myLastRow As Long
Dim myCounter As Long
Dim mySplit As Long
Dim myNewRow As Long
Dim myInsert As Long
Dim myColA As String
Dim myColB As String
Dim myColC As String
Dim myColD As String
Dim myColE As String
' Find last row
End Sub[/html]
_................................................. ....
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 thing correctly. Just an idea from a computer Novice. But anyway the workaround seems to work.
Alan
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...
http://www.excelfox.com/forum/f13/bb...2077/#post9645
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA





Reply With Quote
Bookmarks