录制之前,先选定一个区域
开始录制
把选定区域内容剪切,
在当前位置插入一个表格
把剪切内容粘贴进表格
结束录制
我的 Word 2007 ,录制的结果是这样的
Sub 宏1()
Selection.Cut
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <>"网格型" Then
.Style = "网格型"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With
Selection.PasteAndFormat (wdPasteDefault)
End Sub
只会用excel,wps没用过。这vba要根据需求来定的。下面这个例子供参考。
Option Explicit
Sub カチネ。ミナマ「(MYFILE As String, MYROW As Integer)
Dim myS As String
Dim wdApp, wdDocument
Dim wdTable
Dim i, j, k, L, M As Integer
Dim myArr(1 To 10000) As String
Dim dArr(1 To 10, 1 To 3)
Dim ii As Integer
'myfile = Cells(2, 4)
'myfile = ThisWorkbook.Path &"\" &myfile &".docx"
'Set wdApp = GetObject(, "word.Application") 'ネ。オテトソヌーエェオトwordモヲモテ
'wdApp.Quit
100 Set wdApp = CreateObject("word.application") 'エエスィメサクordモヲモテ
Dim ocell
k = 1
Set wdDocument = wdApp.Documents.Open(MYFILE)
wdDocument.Select
i = wdDocument.Tables.Count
Dim mysArr
For j = 1 To i
Set wdTable = wdDocument.Tables(j)
'For Each ocell In ActiveDocument.Tables(J).Range.Cells 'ラ「メ磴ellsヌーモミクange
For Each ocell In wdTable.Range.Cells 'ラ「メ磴ellsヌーモミクange
'MsgBox ocell.Range.Text
myS = ocell.Range.Text
'mysArr = Split(myS, vbCrLf)
mysArr = Split(myS, Chr(7))
'If Right(myS, 1) = Chr(13) Then
'Do While Right(myS, 1) = Chr(7) Or Right(myS, 1) = Chr(32) Or Right(myS, 1) = Chr(13)
' myS = Mid(myS, 1, Len(myS) - 1)
'Loop
'End If
For ii = 0 To UBound(mysArr)
If Trim(mysArr(ii)) <>"" And Trim(mysArr(ii)) <>Chr(13) Then
'ネ・ウモメイ狃リウオキ釞ーソユク・
If Right(mysArr(ii), 1) = Chr(13) Then
Do While Right(mysArr(ii), 1) = Chr(7) Or Right(mysArr(ii), 1) = Chr(32) Or Right(mysArr(ii), 1) = Chr(13)
mysArr(ii) = Mid(mysArr(ii), 1, Len(mysArr(ii)) - 1)
Loop
End If
myArr(k) = Trim(mysArr(ii))
k = k + 1
End If
Next ii
'myArr(k) = myS
'k = k + 1
Next ocell
Next j
wdApp.Quit
k = k - 1 'kシヌツシwordホトオオオトハセンク
Sheets("sheet3").Select
For i = 1 To k
Cells(i, 1) = i
Cells(i, 2) = myArr(i)
Next i
Sheets("tools").Select
i = 2
Do While Cells(i, 7) <>""
dArr(i - 1, 1) = Cells(i, 7)
dArr(i - 1, 2) = Cells(i, 8)
dArr(i - 1, 3) = Cells(i, 9)
i = i + 1
Loop
i = i - 2 'Iシヌツシカチネ。カヤマトク
Dim tArr
For j = 1 To i
ReDim tArr(1 To dArr(j, 3))
'イ鲽メケリシ・ヨ
For L = 1 To k
If dArr(j, 1) = myArr(L) Then
Exit For
End If
Next L 'Lシヌツシイ鲂スオスケリシ・ヨオトホサヨテ
L = L + dArr(j, 2) + dArr(j, 3) 'ホサヨテオ訒ャユメオスオレメサクセンオトホサヨテ
For M = 1 To dArr(j, 3)
tArr(M) = myArr(L + M - 1)
Next M
'スォイ鲽メオトハヨオミエネ・クカィホサヨテ
Select Case j
Case 1
Sheets("クヒシーナ菁シノ昞ンセモラ。ミナマ「タ・).Select
Cells(MYROW, 2) = tArr(1)
Cells(MYROW, 3) = tArr(2)
Cells(MYROW, 4) = tArr(3)
Sheets("ケ、ラナマ「タ・).Select
Cells(MYROW, 2) = tArr(1)
Cells(MYROW, 3) = tArr(2)
Case 2
Sheets("クヒシーナ菁シノ昞ンセモラ。ミナマ「タ・).Select
Cells(MYROW, 5) = tArr(1)
Cells(MYROW, 6) = tArr(2)
Cells(MYROW, 7) = tArr(3)
Cells(MYROW, 8) = tArr(4)
Cells(MYROW, 10) = tArr(6)
Cells(MYROW, 12) = tArr(7)
Cells(MYROW, 13) = tArr(8)
Sheets("ケ、ラナマ「タ・).Select
Cells(MYROW, 6) = tArr(5)
Case 3
Case 4
Sheets("クヒシーナ菁シノ昞ンセモラ。ミナマ「タ・).Select
Cells(MYROW, 11) = tArr(2)
Case 5
Sheets("ケ、ラナマ「タ・).Select
Cells(MYROW, 4) = tArr(2)
Cells(MYROW, 5) = tArr(3)
Case 6
Sheets("ケ、ラナマ「タ・).Select
Cells(MYROW, 7) = tArr(2)
Cells(MYROW, 8) = tArr(3)
Cells(MYROW, 9) = tArr(4)
Cells(MYROW, 10) = tArr(5)
Cells(MYROW, 11) = tArr(6)
End Select
Next j
End Sub
方法和详细的 *** 作步骤如下:
1、第一步,打开包含4页的word文档,见下图,转到下面的步骤。
2、第二步,完成上述步骤后,如果要快速将光标移至第3页,则可以单击“替换”选项,见下图,转到下面的步骤。
3、第三步,完成上述步骤后,d出一个对话框,单击“定位”选项卡,见下图,转到下面的步骤。
4、第四步,完成上述步骤后,d出一个对话框,单击“定位目标”选项中的“页”选项,在右侧的页面编号栏中输入页号“
3”,然后单击“定位”按钮,见下图,转到下面的步骤。
5、第五步,完成上述步骤后,光标将快速移至页面3的第一行,见下图,转到下面的步骤。
6、第六步,完成上述步骤后,要找到该行,请选择左侧的“行”,然后在右侧输入行号以进行定位,见下图,转到下面的步骤。
7、第七步,完成上述步骤后,就获得了想要的结果了,见下图。这样,就解决了这个问题了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)