以下是引用xxs1025在2004-10-22 21:08:00的发言:
我在实际操作当中发现,用了版主的宏之后,多行的问题解决了,但是列又有对不齐的现象,我仔细观察发现原来在某些方面word的表格当中,本身的列的线有些就没有对齐,有些看上去对起了,但一粘贴到excel当中又对不齐了.有没有办法让word 中表格的列完全自动对齐呢?谢谢!
'都是粘贴惹的祸,有时一不小心就让中文代码成了乱码,让楼主操心了.
Sub TEST()
Dim i As Integer, W1 As Double, W2 As Double, W3 As Double, W4 As Double
Dim w As Double, MyRange As Range
On Error Resume Next
Application.ScreenUpdating = False
With ActiveDocument
Tb = .Tables(1).Columns.Width
For i = 1 To 18
w = .Tables(1).Cell(3, i).Width
If i <= 4 Then
W1 = W1 + w
ElseIf i <= 8 Then
W2 = W2 + w
ElseIf i <= 12 Then
W3 = W3 + w
ElseIf i <= 18 Then
W4 = W4 + w
End If
Next
Set MyRange = .Range(.Paragraphs(1).Range.Start, .Paragraphs(2).Range.End)
MyRange.ConvertToTable Separator:=wdSeparateByTabs
With .Tables(1)
.Style = "网格型"
For i = 1 To 2
.Cell(i, 1).Width = W1
.Cell(i, 2).Width = W2
.Cell(i, 3).Width = W3
.Cell(i, 4).Width = W4
Next
.Cell(Row:=1, Column:=1).Merge _
MergeT=.Cell(Row:=1, Column:=4)
.Rows.Alignment = wdAlignRowCenter
End With
End With
Application.ScreenUpdating = True
End Sub
为了减少此事的再次发生,我编了一个小代码,与大家共享:
Sub GetCopy()
Dim i As Integer, Avs As Object, strSub As String
Set Avs = Application.VBE.SelectedVBComponent
i = Avs.CodeModule.CountOfLines
With Selection
.Collapse Direction:=wdCollapseEnd
For n = 1 To i
strSub = Avs.CodeModule.Lines(n, 1)
.InsertAfter strSub & Chr(13)
Next
.Cut
End With
End Sub
此法原理是将当前代码窗口中的代码逐行插入到当前文档中,最后剪切,然后回到论坛上粘贴.(此代码应置于NORMAL模板中,运行时点VBE中的工具/宏:如图所示:
[此贴子已经被作者于2004-10-23 8:23:17编辑过] |