views:

671

answers:

2

I have a vb .net program that exports information to certain fields of an excel workbook using named ranges. One of the named ranges is a notes section that gets cut off (not visible nor gets printed) if it extends beyond a page break. I am looking for a way to dynamically create new named ranges to accommodate all of the notes' text.

Some other information:

  • The named range is a merged cell from A2:L36 with text wrap enabled

  • Column A is 31 units wide

  • Columns B through L are 8.38 units wide

  • All of the rows are 15.75 units high

  • I do NOT want to print blank pages, resize the font, disable text wrapping, have the end user do any re-formatting, nor change the size of the cells as I have tried these approaches without success.

  • Using Excel 2007

HELP PLEASE!

Thanx in advance! ~8th


forgive my ignorance, I'm still a n00b

A: 

Aaargh! Merged cells are the work of Satan and should be avoided at all costs. Even when their presence is assumed to be benign, they can have subtle and devious ways of wrecking an otherwise sound worksheet.

You don't mention whether the text is being cut off vertically or horizontally?

You should probably look at the AutoFit method as a way to forcing the text to remain inside the printed area. This will resize the cell(s) so that the text fits at your chosen font size and, as the print area is defined by the cell borders, this should ensure that all text remains visible once printed.

If this doesn't work then it might be hard to pin down without getting rid of the merged cells. Are they absolutely necessary?

I am working on a similar worksheet template to yours right now and have cells that resize themselves to fit a wide range of strings up to 911 characters using nothing more than the normal autofit.

Lunatik
Thanks for your feedback Lunatik.The text is getting cut off vertically. I'm not familiar with the AutoFit method but don't think it will be the solution to my problem because as I stated before, I dont' want to have to force the text into a predefined space. The amount of text in the notes section will vary therefore in theory, it should be able to accomodate an unlimited amount of text. I am still looking into a fix for this so if I come up with a solution, I'll post it here!
8thWonder
I should have made it clear that the Autofit method works on the cell size, not the text. It changes the row/column size to fit the text contained within so sounds like a perfect solution. Each cell (including each within a merged cell) can be up to 409 points high and 255 wide, so surely must be able to display the intended text?
Lunatik
A: 

Thanks again Lunatik for your response. I was able to come up with an acceptable workaround before I saw your most recent post. This is not the most graceful solution but it is most suitable for what I was trying to accomplish. I hope this can be of some use to someone else in the future.

Dim sNotes As String = g_strProgram.sNotes
Dim iStartIndex, iEndIndex As Integer
Dim iRow As Integer = 0

If (sNotes.Length > 0) Then
   g_frmMain.ucAdditionalInfo.txtNotes.Text = sNotes
   Do
      iRow += 1
      oWorkSheet.Range("A" & iRow + 1 & ":L" & iRow + 1).Merge()
      iStartIndex = IIf(iRow = 1, 0, iEndIndex + 1)

      If (g_frmMain.ucAdditionalInfo.txtNotes.GetFirstCharIndexFromLine(iRow) >= 0) Then
         iEndIndex = g_frmMain.ucAdditionalInfo.txtNotes.GetFirstCharIndexFromLine(iRow) - 1
      Else
         iEndIndex = g_strProgram.sNotes.Length - 1
      End If

      oWorkSheet.Range("ProgramNote").Offset(iRow, 0).Value = g_strProgram.sNotes.Substring(iStartIndex, iEndIndex - iStartIndex).TrimEnd(vbCrLf)
   Loop While (iEndIndex < g_strProgram.sNotes.Length - 1)
Else
       oWorkSheet.Visible = Excel.XlSheetVisibility.xlSheetHidden
End If

If anyone out there reading this needs clarification with any of the aforementioned, do not hesitate to post a question here! ~8th

8thWonder