Sub export_ti_an_report()
Dim tmpFilePath As String
tmpFilePath = ThisWorkbook.Path & "\公司提案承辦表模板.wpt"
If Not FileExists(tmpFilePath) Then
MsgBox ("導(dǎo)出失?。? & vbNewLine & "當(dāng)前目錄下沒(méi)有找到導(dǎo)出模板文件“公司提案承辦表模板.wpt”!" & vbNewLine & "請(qǐng)將導(dǎo)出模板文件“公司提案承辦表模板.wpt”放到當(dāng)前文件目錄下。")
Exit Sub
End If
Dim activeRow As Integer
'Dim activeColumn As Integer
' 獲取活動(dòng)單元格的行號(hào)和列號(hào)
activeRow = ActiveCell.Row
'activeColumn = ActiveCell.Column
If activeRow < 3 Then
Exit Sub
End If
If Sheets("提案數(shù)據(jù)庫(kù)").Range("A3").Value & "CS" = "CS" Then
MsgBox ("當(dāng)前行沒(méi)有需要保存的公司提案承辦表!請(qǐng)檢查。")
Exit Sub
End If
result = MsgBox("你確定要導(dǎo)出公司提案承辦表到WPS文件嗎?", vbYesNo, "確認(rèn)對(duì)話框")
' 檢查用戶的選擇
If result = vbNo Then
Exit Sub
End If
Dim wordApp As Object
Dim wordDoc As Object
Dim findText As String
Dim replaceText As String
' 創(chuàng)建Word應(yīng)用程序?qū)ο?/p>
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("提案數(shù)據(jù)庫(kù)").Range("A" & i).Value & "CS" <> "CS" Then
oTable.Rows.Add '然后按照統(tǒng)計(jì)的行數(shù)進(jìn)行對(duì)第5個(gè)表格當(dāng)中進(jìn)行行的插入
oTable.Cell(i + 1, 1).Range.Text = Sheets("提案數(shù)據(jù)庫(kù)").Range("C" & i).Value
oTable.Cell(i + 1, 2).Range.Text = Sheets("提案數(shù)據(jù)庫(kù)").Range("D" & i).Value
oTable.Cell(i + 1, 3).Range.Text = Sheets("提案數(shù)據(jù)庫(kù)").Range("I" & i).Value
oTable.Cell(i + 1, 4).Range.Text = Sheets("提案數(shù)據(jù)庫(kù)").Range("J" & i).Value
Else
Exit For
End If
Next
'刪除首行,首行用于儲(chǔ)存數(shù)據(jù)行格式信息
Set oRow = oTable.Rows(2) ' Word中的行索引從1開始
oRow.Delete
' 關(guān)閉Word文檔和應(yīng)用程序
Dim fileName As String
fileName = "D:\公司提案承辦表(" & Year(Date) & "年" & Month(Date) & "月).wps" ' 修改為輸出文件的實(shí)際路徑
wordDoc.SaveAs fileName
wordDoc.Close
wordApp.Quit
' 釋放對(duì)象
Set wordDoc = Nothing
Set wordApp = Nothing
MsgBox "已將文件保存到:“" & fileName & "”"
End Sub