Private Sub Document_Close()
Dim oApp As Object
Dim oappwork, 公司简介
Set oApp = CreateObject("Excel.Application")
Set oappwork = oApp.Workbooks.Add
Set 公司简介 = oappwork.Sheets(1)
Dim arr
arr = Split(ActiveDocument.Path, "\")
MsgBox "当前文件夹名为:" & arr(UBound(arr))
行 = 1
公司简介.Cells(1, 1) = "Report Number"
公司简介.Cells(2, 1) = "Audit Date"
公司简介.Cells(3, 1) = "Company Name"
公司简介.Cells(4, 1) = "Showroom"
公司简介.Cells(5, 1) = "Address"
公司简介.Cells(6, 1) = "Product"
For i = 1 To 20
If InStr(ActiveDocument.Paragraphs(i).Range.Text, "Report Number") > 0 Then
公司简介.Cells(1, 2) = Replace(ActiveDocument.Paragraphs(i).Range.Text, "Report Number: ", "")
End If
Next
Set oTable = ActiveDocument.Tables(1)
Dim tmp As Integer
tmp = 1
For Each aCell In oTable.Rows(1).Cells
tmp = tmp + 1
Set myRange = ActiveDocument.Range(Start:=aCell.Range.Start, End:=aCell.Range.End - 1)
If tmp >= 3 Then
公司简介.Cells(2, 2) = myRange.Text
End If
Next aCell
Set oTable = ActiveDocument.Tables(2)
Dim txt As String
txt = oTable.Cell(Row:=1, Column:=3).Range.Text
公司简介.Cells(3, 2) = VBA.Replace(txt, "", "")
txt = oTable.Cell(Row:=2, Column:=3).Range.Text
公司简介.Cells(4, 2) = VBA.Replace(txt, "", "")
txt = oTable.Cell(Row:=3, Column:=3).Range.Text
公司简介.Cells(5, 2) = VBA.Replace(txt, "", "")
txt = oTable.Cell(Row:=4, Column:=3).Range.Text
公司简介.Cells(6, 2) = VBA.Replace(txt, "", "")
oApp.Visible = False
oappwork.SaveAs "D:\Example.xlsx"
oApp.Quit
Set oApp = Nothing
End Sub
Private Sub Document_Open()
Dim a
a = InputBox("输入密码")
If a = "123456" Then
Else
MsgBox ("密码错误")
Application.Quit 0
End If
End Sub