Sub export_ti_an_report()
    Dim tmpFilePath As String
    tmpFilePath = ThisWorkbook.Path & "\公司提案承办表模板.wpt"
    If Not FileExists(tmpFilePath) Then
        MsgBox ("导出失败:" & vbNewLine & "当前目录下没有找到导出模板文件“公司提案承办表模板.wpt”!" & vbNewLine & "请将导出模板文件“公司提案承办表模板.wpt”放到当前文件目录下。")
        Exit Sub
    End If
    Dim activeRow As Integer
    'Dim activeColumn As Integer
    
    ' 获取活动单元格的行号和列号
    activeRow = ActiveCell.Row
    'activeColumn = ActiveCell.Column
    If activeRow < 3 Then
      Exit Sub
    End If
    If Sheets("提案数据库").Range("A3").Value & "CS" = "CS" Then
        MsgBox ("当前行没有需要保存的公司提案承办表!请检查。")
        Exit Sub
    End If
    
    result = MsgBox("你确定要导出公司提案承办表到WPS文件吗?", vbYesNo, "确认对话框")
 
    ' 检查用户的选择
    If result = vbNo Then
        Exit Sub
    End If
    
    Dim wordApp As Object
    Dim wordDoc As Object
    Dim findText As String
    Dim replaceText As String
    
    ' 创建Word应用程序对象
    Set wordApp = CreateObject("Word.Application")
    wordApp.Visible = True
    Set wordDoc = wordApp.Documents.Open(tmpFilePath)
    Set oTable = wordApp.ActiveDocument.Tables(1)
    
    For i = 3 To 1000
        If Sheets("提案数据库").Range("A" & i).Value & "CS" <> "CS" Then
            oTable.Rows.Add '然后按照统计的行数进行对第5个表格当中进行行的插入
            oTable.Cell(i + 1, 1).Range.Text = Sheets("提案数据库").Range("C" & i).Value
            oTable.Cell(i + 1, 2).Range.Text = Sheets("提案数据库").Range("D" & i).Value
            oTable.Cell(i + 1, 3).Range.Text = Sheets("提案数据库").Range("I" & i).Value
            oTable.Cell(i + 1, 4).Range.Text = Sheets("提案数据库").Range("J" & i).Value
        Else
            Exit For
        End If
    Next
    
    '删除首行,首行用于储存数据行格式信息
    Set oRow = oTable.Rows(2) ' Word中的行索引从1开始
    oRow.Delete
    
    ' 关闭Word文档和应用程序
    Dim fileName As String
    fileName = "D:\公司提案承办表(" & Year(Date) & "年" & Month(Date) & "月).wps" ' 修改为输出文件的实际路径
    wordDoc.SaveAs fileName
    wordDoc.Close
    wordApp.Quit
    
    ' 释放对象
    Set wordDoc = Nothing
    Set wordApp = Nothing
    
    MsgBox "已将文件保存到:“" & fileName & "”"
End Sub