Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2006

Tip: Looking for answers? Try searching our database.

pre-Formatted auto-generated Excel sheet

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jamesftoland@gmail.com - 17 Jan 2006 18:35 GMT
Hello,

I have a macro that generates table information form Word into an excel
sheet, and I'd like it if the cells columns would text wrap the data in
the cells, as well as display the regular "medium" black Excel
gridlines....not sure where to introduce this code, as .Columns or
.Rows? Anyway, here is what I have that needs to be tweaked...Thanks
again all, I'm learning....

Next

     .Columns("A:A").EntireColumn.AutoFit
     .Columns("A:A").WrapText = True

     .Columns("B:B").EntireColumn.AutoFit
     .Columns("B:B").WrapText = True

     .Columns("C:C").EntireColumn.AutoFit
     .Columns("C:C").WrapText = True

   Cell.Borders (xlEdgeLeft)
       Border.LineStyle = xlContinuous
       Border.Weight = xlThin
       Border.ColorIndex = xlAutomatic
   Cell.Borders (xlEdgeTop)
       Border.LineStyle = xlContinuous
       Border.Weight = xlThin
       Border.ColorIndex = xlAutomatic
  Cell.Borders (xlEdgeBottom)
       Border.LineStyle = xlContinuous
       Border.Weight = xlThin
       Border.ColorIndex = xlAutomatic
Cell.Borders (xlEdgeRight)
       Border.LineStyle = xlContinuous
       Border.Weight = xlThin
       Border.ColorIndex = xlAutomatic
Cell.Borders (xlInsideVertical)
       Border.LineStyle = xlContinuous
       Border.Weight = xlThin
       Border.ColorIndex = xlAutomatic
Cell.Borders (xlInsideHorizontal)
       Border.LineStyle = xlContinuous
       Border.Weight = xlThin
       Border.ColorIndex = xlAutomatic

End With
Jay Taplin - 18 Jan 2006 03:39 GMT
I would implement this code as such:

   With Range("C5:D10") 'Could change this to "With Selection" (no quotes)
       .WrapText = True

       .Borders(xlDiagonalDown).LineStyle = xlNone
       .Borders(xlDiagonalUp).LineStyle = xlNone

       With .Borders(xlEdgeLeft)
           .LineStyle = xlContinuous
           .Weight = xlMedium
           .ColorIndex = xlAutomatic
       End With

       With .Borders(xlEdgeTop)
           .LineStyle = xlContinuous
           .Weight = xlMedium
           .ColorIndex = xlAutomatic
       End With

       With .Borders(xlEdgeBottom)
           .LineStyle = xlContinuous
           .Weight = xlMedium
           .ColorIndex = xlAutomatic
       End With

       With .Borders(xlEdgeRight)
           .LineStyle = xlContinuous
           .Weight = xlMedium
           .ColorIndex = xlAutomatic
       End With

       On Error Resume Next

       With .Borders(xlInsideVertical)
           .LineStyle = xlContinuous
           .Weight = xlMedium
           .ColorIndex = xlAutomatic
       End With

       With .Borders(xlInsideHorizontal)
           .LineStyle = xlContinuous
           .Weight = xlMedium
           .ColorIndex = xlAutomatic
       End With

       On Error GoTo 0
   End With

Please note that the line that states "With Range("C5:D10")" could be
changed "With Selection" (no quotes), so whenever you run the macro it would
work against the selected cells.

Secondly, if I'm understand your intentions, I would not use the AutoFit
method, as this will size your columns out to the maximum width of your
text, then enable wrapping.  Ultimately, nothing will be wrapped, unless if
you modify the text later, as the column is already wide enough to
accomodate all the text in it.

Finally, the rest of the code looked pretty good.  I added the appropriate
dots (".") to reference the objects and added error handling in the case
that you are only updating the style of one cell.

If you need any more help, please post back.

Jay Taplin MCP
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.