|
kevinchan2006 发表于 2012-12-20 13:26
再次求教版主,请问下面的代码有什么作用?我看不懂。为什么要这么做呢?我把那个2改成1或者3都不能运行。 ...
Word表格中的文本后面有回车键和"",它们的asc码分表示13和7,你在原Word文档中运行一下下面代码就知道了:- Sub AA()
- Dim projectno As String
- Dim excelobject As Object, wb As Object, r As Long, i As Long, arr
- projectno = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1, 2).Range
- MsgBox Asc(Right(projectno, 2))
- MsgBox Asc(Right(projectno, 1))
- MsgBox Chr(Asc(Right(projectno, 1)))
- projectno = Left(projectno, Len(projectno) - 2)
-
- ' Set excelobject = CreateObject("excel.application") '启动Excel程序
- ' excelobject.Visible = False '不可见
- ' Set wb = excelobject.Workbooks.Open(ActiveDocument.Path & "\project.xls")
- ' On Error Resume Next
- ' r = excelobject.WorksheetFunction.Match(projectno, wb.Sheets(1).Columns(1), 0)
- ' If Err = 0 Then
- ' arr = wb.Sheets(1).Cells(r, 2).Resize(, 4)
- ' With ActiveDocument.Tables(1)
- ' For i = 1 To 4
- ' .Cell(i, 2).Range = arr(1, i)
- ' Next
- ' End With
- ' End If
- ' excelobject.Quit
- End Sub
复制代码 |
|