Workaround 2: To get over the vaniishing carrriage returns in Code in HTML or PHP Cod
Just some further Testing, as I may have another solution to the problem of codes pasted into a HTML ( or PHP ) Window "Loosing" a carriage return"
To remind ( me! ) of what i am testing out here: Sometimes it is better to use A HTML ( or PHP ) Code window rather than a BB Code Window to paste in a Forum Post. This can be the case, for example, when a Code itself contains text strings which may have BB Code Tags in. ( The Code tags usually are recognised as just that giving some peculiar results. )
This Code for example, shown here excactly as I want it, would get messed up in a code Window
Sub CodeLinesInHTMLWindowLoosingCarriageReturns()
1 'Line 1
2 'Line 2
3 'Line 3
4 Dim strBBCodeTag As String
5 Let strBBCodeTag = "[color=lightsalmon]A Text in Forum Post to come out Light Salmon in Color[/color]"
End Sub
_................................................. ....
Pasted in a code Window:
Code:
Sub CodeLinesInHTMLWindowLoosingCarriageReturns()1 'Line 1
2 'Line 2
3 'Line 3
4 Dim strBBCodeTag As String
5 Let strBBCodeTag = "A Text in Forum Post to come out Light Salmon in Color"
End Sub
You see the BB Code String was evaluated literally as BB Code. - The BB Code string is messed up as I do not want
_.............................................
It is found that pasting in a HTML Code window instead can give you this
HTML Code:
Sub CodeLinesInHTMLWindowLoosingCarriageReturns()
1 'Line 1
2 'Line 2
3 'Line 3
4 Dim strBBCodeTag As String
5 Let strBBCodeTag = "[color=lightsalmon]A Text in Forum Post to come out Light Salmon in Color[/color]"
End Sub
which is again what I wanted
_...............................................
But if you paste directly by copying from the VB Editor ( Ctrl C ) and pasting in the forum Editor in HTML Code tags, then you can get this instead.
HTML Code:
Sub CodeLinesInHTMLWindowLoosingCarriageReturns()1 'Line 12 'Line 23 'Line 34 Dim strBBCodeTag As String5 Let strBBCodeTag = "[color=lightsalmon]A Text in Forum Post to come out Light Salmon in Color[/color]"End Sub
. here the carriage returns have „vanished!!!!“
_................................................. ..................................
_ I noticed and demonstrated that you can get over this sometimes by “doing a stop over “ in between at a a Word Document, that is to say pasting into a Word document first , then re – copying that to the clipboard and pasting that into the Forum Editor.
http://www.excelfox.com/forum/f17/te...2079/#post9641
http://www.excelfox.com/forum/f13/bb...2077/#post9645
_..............................................
OK that was one “workaround”..... _The other Day I had a similar problem (_.......... with a code i did to overcome the problem of the Forum Editor “eating” spaces of greater than two. )
Eileen's Lounge • View topic - Word VBA Replace multiple Spaces in Text with BB Code String
_...............)
_ Some how this “loss of a carriage return crept in when pasted into a Post, ( even though in Word or in a displayed Message Box, the text i wanted to past in seemed OK ).
_ After a bit of experimenting I tried a modification which was basically this code line
= Replace((Text), vbCr, vbCr & vbLf, 1, -1) 'In Text~~,~~~replce a vbCr~~~,~~~with a vbCr & vbLf~~~~,~~~~the returned string should start at position 1 of the original ( so whole string returned )(Note: the number is not just where you start replacing- it is also where the returned String may start-so a number greater than 1 will "chop" bits off returning a string of reduced length compared with the original~~~,~~~-1~~indicates replace all occurrences
Writing a code to do something similar to the text held in the Clipboard appears to do something similar ( Not quite the same .. here what the Message box shows for the “Before” and “after” is different, which was not the case with the modification to the “preventing Forum editor eating spaces more than 2 codes” . Clearly the vbCr and vbLf is a trick one.. )
_.................
So Finally
_ If you wish to use the HTML Code Window rather than the BB Code Window when posting a Code in a Forum Thread.... you
_ Copy the code from the VB Editor, ( Ctrl C )
_ Run this code, ( which works on and modifies the text in the Clipboard.
Code:
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
_ Paste into the Forum Thread an enclose in HTML Code Tags..This comes out:
HTML Code:
Sub CodeLinesInHTMLWindowLoosingCarriageReturns()
1 'Line 1
2 'Line 2
3 'Line 3
4 Dim strBBCodeTag As String
5 Let strBBCodeTag = "[color=lightsalmon]A Text in Forum Post to come out Light Salmon in Color[/color]"
End Sub
PHP Code:
Sub CodeLinesInHTMLWindowLoosingCarriageReturns()
1 'Line 1
2 'Line 2
3 'Line 3
4 Dim strBBCodeTag As String
5 Let strBBCodeTag = "[color=lightsalmon]A Text in Forum Post to come out Light Salmon in Color[/color]"
End Sub
Alan
_..................................
Trying to Explain to Pike about Posting BB Code Genarator VBA Codes in Forum Posts
Hi Pike, :confused:
I really do appreciate you taking the time to reply and give all of that info. It sounds very intersting. Thanks :) . Sadly , I am a computer novice, and do not really understand. I get only the general point. It certainly sounds like the code snippet you gave could come in handy to further improve your great BB Code Genarator Code. Sadly I lack the ability to incorporate that in your code. I lack the basic understanding. I do not really understand what you are talking about.......
Quote:
Originally Posted by
pike
.......
Your question is about excel cell string which split string with carriage return[s] and converting to BBcode via VBA.
......
...... No That was not anything like my question ( i think :confused: ). You have given some fantasic answers but have completely missed my point. Sorry if i have explained so badly.....
I try again:
I did some more tests for you, just now to try to get accross what I am talking about. Once again: It is all to do with how to share your code in a Forum - that is to say what Code Tags to use. Your BB Code Genarator Code is a VBA Code, so normally we would use the normal BB Code Tags ( from icon # above ).....
But....
Quote:
Originally Posted by
DocAElstein
Basically the point is this:
-1) Your BB Code Genarator Code which is the point of this Thread ( and which is a VBA Code ) , will **usually not come out properly in a BB Code Window. So we use a HTML or PHP Code Window as an exception for this type of VBA Code, - that is to say a VBA Code where there are strings inside it with BB Code bits in it ( the square bracket stuff)
(_.. -2) Very occaisionally, ( and not often anymore ), there were also some additional problems when using a HTML window to post your BB Code Genarator Code. I gave a couple of work arounds to that. (Note that this post is from a few Month's ago and there were some updates in Forum Software in the maentime, effecting Code Windows, such as the scroll bar which suddenly appeared in many Forums that did not have it:
http://www.excelfox.com/forum/f17/code-tag-test-with-long-comments-1976/#post9664
from Post # 50 http://www.mrexcel.com/forum/about-b...sh-list-5.html
_.....)
What you are talkng about does sound very interseting and useful. But it is something completely different. ( i think:confused: )
If you check out those tests I just did for you, then I think it should be obvious what I was getting at...
I am so very greatful that you take the time to give me such great ( unfortunately above my head partly ) info. So sorry it is not relavent to what I was trying to get across. Hope those extra tests will help.
Alan
_.........
**P.s. I note that in some of your referrences, for example
Convert Excel range to BBCode Table - Page 2
then in the code window you are using there, "VB:" , you do not experience the problems that I have been referring to. But as I have endeavoured to explain, you will get problems at MrExcel, ExcelFox, and ExcelForum if you attempt to post your VBA BBcode generator in normal BB Code Tags. It would appear that at Ozgrid your "normal" Code Window is different to that at MrExcel ExcelForum and ExcelFox. I have no account at, or experience with, Ozgrid Forum
_.....
P.P.s
Since the last time we spoke last January generally about BB Code Generators, the Theme came up a bit in some Threads.. may be just of passing interest...
How to post a range - headers and data? [SOLVED] - Page 17
Tags for Coloring Table cells for EXCELFORUM [SOLVED]
I updated the File I gave you, to include some of the new Codes presented.
https://app.box.com/s/zhz7awdag4nl1zs6564s9zzcwp50e4w9