Results 1 to 8 of 8

Thread: [RESOLVED] WordWrap In Excel

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Resolved [RESOLVED] WordWrap In Excel

    I have the following lines of code in VB6
    VB Code:
    1. shWorkSheet.Range("A29") = "Comments"
    2.         shWorkSheet.Columns("A:BZ").AutoFit
    3.         bkWorkBook.Worksheets(1).Columns(30).WrapText = True
    4.         shWorkSheet.Range("A30") = txtComments.Text
    5.         bkWorkBook.Worksheets(1).Columns(30).ColumnWidth = 12
    txtComments is a multiline text box and I need to display the contents in an Excel spreadsheet as a block of text.

    Right now, the comments are all in row 30 and spreading across in a single line to about column I or J.

    What modifications do I need to make?

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: WordWrap In Excel

    Hack
    Can you post a screenshot of the s/sheet? I'm having a hard time visualizing your data layout.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: WordWrap In Excel

    The only way I could save it small enough to fit as an attachment was to save it as monochrome, but you should get the idea. As you can see, the comments just scroll in a straight line completely off the screen.
    Attached Images Attached Images  

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: WordWrap In Excel

    Change your code
    VB Code:
    1. shWorkSheet.Range("A29") = "Comments"
    2.         shWorkSheet.Columns("A:BZ").AutoFit
    3.         bkWorkBook.Worksheets(1).Columns(30).WrapText = True
    4.         shWorkSheet.Range("A30") = txtComments.Text
    5.         bkWorkBook.Worksheets(1).Columns(30).ColumnWidth = 12
    to
    VB Code:
    1. shWorkSheet.Range("A29") = "Comments"
    2. shWorkSheet.Columns("A:BZ").AutoFit
    3. With shWorkSheet.Range("A30")
    4.     .Value = txtComments.Text
    5.     .WrapText = True
    6.     .ColumnWidth = 20 'You will need to tweak the width
    7.     .RowHeight = 20 'You will need to tweak the height
    8. End With

    This will allow you to adjust the height and width of the comments cell.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: WordWrap In Excel

    Hack
    One small change. Rather than manually setting both the width and the height, I would suggest you set the width to your desired value and then AutoFit the height to ensure that the entire comments block is visible.
    VB Code:
    1. .ColumnWidth = 20 'You will need to tweak the width
    2.     .Row.AutoFit 'Ensures that all data is visible
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  6. #6

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: WordWrap In Excel

    Quote Originally Posted by DKenny
    Hack
    One small change. Rather than manually setting both the width and the height, I would suggest you set the width to your desired value and then AutoFit the height to ensure that the entire comments block is visible.
    VB Code:
    1. .ColumnWidth = 20 'You will need to tweak the width
    2.     .Row.AutoFit 'Ensures that all data is visible
    VB Code:
    1. With shWorkSheet.Range("A30")
    2.             .Value = txtComments.Text
    3.             .WrapText = True
    4.             .ColumnWidth = 40
    5.             .Row.AutoFit '<==== error:  Invalid Qualifier
    6.         End With
    I've been playing around and it seems a RowHeight = 40 and a ColumnWidth = 40 should suit my needs.

    However, I like the AutoFit thing, but I get the above stated error message when I tried to use it.
    Last edited by Hack; May 9th, 2006 at 11:51 AM.

  7. #7
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: WordWrap In Excel

    My bad, change .Row to .EntireRow and the AutoFit method will work.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  8. #8

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: WordWrap In Excel

    Quote Originally Posted by DKenny
    My bad, change .Row to .EntireRow and the AutoFit method will work.
    Dude, you are on my Christmas card list!

    That worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width