To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Office Development

Reply Post New Thread
 
Thread Tools Display Modes
Old Nov 14th, 2009, 11:00 PM   #1
Fonty
Addicted Member
 
Fonty's Avatar
 
Join Date: May 06
Location: Mexico City
Posts: 148
Fonty is an unknown quantity at this point (<10)
Post Wrap text

Suppose you have a cell with the following value: "Line one and line 2". You set the format of the cell to wrap text and you change its size so that it looks like:

Line one and
line 2

Is it possible in vba to extract tomething like "Line one and" & vbLine & "line 2"?
I think you can somehow deduce how many rows the cell has if you use my_rows=round(cell(1,1).height / cell(1,1).font.size, 0) so you can actually know how many vbLine to use. But still it's incomplete...
Fonty is offline   Reply With Quote
Old Nov 15th, 2009, 12:38 AM   #2
westconn1
PowerPoster
 
Join Date: Dec 04
Posts: 13,424
westconn1 is a splendid one to behold (700+)westconn1 is a splendid one to behold (700+)westconn1 is a splendid one to behold (700+)westconn1 is a splendid one to behold (700+)westconn1 is a splendid one to behold (700+)westconn1 is a splendid one to behold (700+)westconn1 is a splendid one to behold (700+)
Re: Wrap text

i played with this, but it is not correct
vb Code:
  1. Dim r As Range, myarr() As String
  2. Set r = Range("A3")
  3. linecnt = Len(r) \ r.ColumnWidth
  4. ReDim myarr(linecnt)
  5. awords = Split(r)
  6. tmp = awords(0) & " "
  7. j = 0
  8. For i = 1 To UBound(awords)
  9.     If Len(tmp) + Len(awords(i)) > r.ColumnWidth + 1 Then
  10.         myarr(j) = tmp
  11.         j = j + 1
  12.         tmp = awords(i) & " "
  13.     Else
  14.         tmp = tmp & awords(i) & " "
  15.     End If
  16. Next
  17. myarr(j) = tmp
unfortunately vba has no objects with textwidth property to work with, so i do not know anyway to get the accurate width of a string
also excel will wrap words at point where there is no space if the word is too long and i did not test for that, though it could be done
__________________
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

come back and mark your original post as resolved if your problem is fixed
pete
westconn1 is online now   Reply With Quote
Old Nov 16th, 2009, 05:04 AM   #3
westconn1
PowerPoster
 
Join Date: Dec 04
Posts: 13,424
westconn1 is a splendid one to behold (700+)westconn1 is a splendid one to behold (700+)westconn1 is a splendid one to behold (700+)westconn1 is a splendid one to behold (700+)westconn1 is a splendid one to behold (700+)westconn1 is a splendid one to behold (700+)westconn1 is a splendid one to behold (700+)
Re: Wrap text

i have been able to make this work, but it will return the lines as displayed in cells edit mode may change slightly after leaving the cell

requires use of activex dll
__________________
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

come back and mark your original post as resolved if your problem is fixed
pete
westconn1 is online now   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Office Development


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:39 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.