|
朋友给了一段这样的代码,请大神帮忙解释下呀,谢谢!!!
Sub obj()
Dim objWord As Object
Dim FileStart
Dim FileNew
Set objWord = CreateObject("Word.Application")
FileSt = "C:\My_acts_template\_act_template_12.dotx"
FileNew = "C:\My_acts_template\act template_2.docx"
Set objDoc = objWord.Documents.Open(FileSt)
objWord.Visible = True
objDoc.Bookmarks("ACT_DATE").Range.InsertAfter (Cells(3, 3).Value)
objDoc.Bookmarks("ACT_DATE_0").Range.InsertAfter (Cells(3, 3).Value)
objDoc.Bookmarks("invoice_date_1").Range.InsertAfter (Cells(3, 10).Value)
objDoc.Bookmarks("invoice_date_2").Range.InsertAfter (Cells(4, 10).Value)
objDoc.Bookmarks("invoice_date_3").Range.InsertAfter (Cells(5, 10).Value)
objDoc.Bookmarks("invoice_date_4").Range.InsertAfter (Cells(6, 10).Value)
objDoc.Bookmarks("invoice_date_5").Range.InsertAfter (Cells(7, 10).Value)
objDoc.Bookmarks("invoice_date_6").Range.InsertAfter (Cells(8, 10).Value)
objDoc.Bookmarks("invoice_date_7").Range.InsertAfter (Cells(9, 10).Value)
objDoc.Bookmarks("invoice_date_8").Range.InsertAfter (Cells(10, 10).Value)
objDoc.Bookmarks("invoice_number_1").Range.InsertAfter (Cells(3, 11).Value)
objDoc.Bookmarks("invoice_number_2").Range.InsertAfter (Cells(4, 11).Value)
objDoc.Bookmarks("invoice_number_3").Range.InsertAfter (Cells(5, 11).Value)
objDoc.Bookmarks("invoice_number_4").Range.InsertAfter (Cells(6, 11).Value)
objDoc.Bookmarks("invoice_number_5").Range.InsertAfter (Cells(7, 11).Value)
objDoc.Bookmarks("invoice_number_6").Range.InsertAfter (Cells(8, 11).Value)
objDoc.Bookmarks("invoice_number_7").Range.InsertAfter (Cells(9, 11).Value)
objDoc.Bookmarks("invoice_number_8").Range.InsertAfter (Cells(10, 11).Value)
objDoc.Bookmarks("Invoice_amount_1").Range.InsertAfter (Cells(3, 14).Text)
objDoc.Bookmarks("Invoice_amount_2").Range.InsertAfter (Cells(4, 14).Text)
objDoc.Bookmarks("Invoice_amount_3").Range.InsertAfter (Cells(5, 14).Text)
objDoc.Bookmarks("Invoice_amount_4").Range.InsertAfter (Cells(6, 14).Text)
objDoc.Bookmarks("Invoice_amount_5").Range.InsertAfter (Cells(7, 14).Text)
objDoc.Bookmarks("Invoice_amount_6").Range.InsertAfter (Cells(8, 14).Text)
objDoc.Bookmarks("Invoice_amount_7").Range.InsertAfter (Cells(9, 14).Text)
objDoc.Bookmarks("Invoice_amount_8").Range.InsertAfter (Cells(10, 14).Text)
objDoc.Bookmarks("Invoice_Balance_1").Range.InsertAfter (Cells(3, 13).Text)
objDoc.Bookmarks("Invoice_Balance_2").Range.InsertAfter (Cells(4, 13).Text)
objDoc.Bookmarks("Invoice_Balance_3").Range.InsertAfter (Cells(5, 13).Text)
objDoc.Bookmarks("Invoice_Balance_4").Range.InsertAfter (Cells(6, 13).Text)
objDoc.Bookmarks("Invoice_Balance_5").Range.InsertAfter (Cells(7, 13).Text)
objDoc.Bookmarks("Invoice_Balance_6").Range.InsertAfter (Cells(8, 13).Text)
objDoc.Bookmarks("Invoice_Balance_7").Range.InsertAfter (Cells(9, 13).Text)
objDoc.Bookmarks("Invoice_Balance_8").Range.InsertAfter (Cells(10, 13).Text)
objDoc.Bookmarks("Amout_to_deduct_1").Range.InsertAfter (Cells(3, 12).Text)
objDoc.Bookmarks("Amout_to_deduct_2").Range.InsertAfter (Cells(4, 12).Text)
objDoc.Bookmarks("Amout_to_deduct_3").Range.InsertAfter (Cells(5, 12).Text)
objDoc.Bookmarks("Amout_to_deduct_4").Range.InsertAfter (Cells(6, 12).Text)
objDoc.Bookmarks("Amout_to_deduct_5").Range.InsertAfter (Cells(7, 12).Text)
objDoc.Bookmarks("Amout_to_deduct_6").Range.InsertAfter (Cells(8, 12).Text)
objDoc.Bookmarks("Amout_to_deduct_7").Range.InsertAfter (Cells(9, 12).Text)
objDoc.Bookmarks("Amout_to_deduct_8").Range.InsertAfter (Cells(10, 12).Text)
objDoc.Bookmarks("VAT_1").Range.InsertAfter (Cells(3, 17).Text)
objDoc.Bookmarks("VAT_2").Range.InsertAfter (Cells(4, 17).Text)
objDoc.Bookmarks("VAT_3").Range.InsertAfter (Cells(5, 17).Text)
objDoc.Bookmarks("VAT_4").Range.InsertAfter (Cells(6, 17).Text)
objDoc.Bookmarks("VAT_5").Range.InsertAfter (Cells(7, 17).Text)
objDoc.Bookmarks("VAT_6").Range.InsertAfter (Cells(8, 17).Text)
objDoc.Bookmarks("VAT_7").Range.InsertAfter (Cells(9, 17).Text)
objDoc.Bookmarks("VAT_8").Range.InsertAfter (Cells(10, 17).Text)
objDoc.Bookmarks("CONTRACT_0_1").Range.InsertAfter (Cells(3, 2).Value)
objDoc.Bookmarks("CONTRACT_0_2").Range.InsertAfter (Cells(4, 2).Value)
objDoc.Bookmarks("CONTRACT_0_3").Range.InsertAfter (Cells(5, 2).Value)
objDoc.Bookmarks("CONTRACT_0_4").Range.InsertAfter (Cells(6, 2).Value)
objDoc.Bookmarks("CONTRACT_0_5").Range.InsertAfter (Cells(7, 2).Value)
objDoc.Bookmarks("CONTRACT_0_6").Range.InsertAfter (Cells(8, 2).Value)
objDoc.Bookmarks("CONTRACT_0_7").Range.InsertAfter (Cells(9, 2).Value)
objDoc.Bookmarks("CONTRACT_0_8").Range.InsertAfter (Cells(10, 2).Value)
objDoc.Bookmarks("CONTRACT_0_9").Range.InsertAfter (Cells(11, 2).Value)
objDoc.Bookmarks("CONTRACT_0_10").Range.InsertAfter (Cells(12, 2).Value)
objDoc.Bookmarks("CONTRACT_0_11").Range.InsertAfter (Cells(13, 2).Value)
objDoc.Bookmarks("CONTRACT_0_12").Range.InsertAfter (Cells(14, 2).Value)
objDoc.Bookmarks("CONTRACT_0_13").Range.InsertAfter (Cells(15, 2).Value)
objDoc.Bookmarks("CONTRACT_0_14").Range.InsertAfter (Cells(16, 2).Value)
objDoc.Bookmarks("CONTRACT_0_15").Range.InsertAfter (Cells(17, 2).Value)
objDoc.Bookmarks("ACT_AMOUNT_0_1").Range.InsertAfter (Cells(3, 4).Text)
objDoc.Bookmarks("ACT_AMOUNT_0_2").Range.InsertAfter (Cells(4, 4).Text)
objDoc.Bookmarks("ACT_AMOUNT_0_3").Range.InsertAfter (Cells(5, 4).Text)
objDoc.Bookmarks("ACT_AMOUNT_0_4").Range.InsertAfter (Cells(6, 4).Text)
objDoc.Bookmarks("ACT_AMOUNT_0_5").Range.InsertAfter (Cells(7, 4).Text)
objDoc.Bookmarks("ACT_AMOUNT_0_6").Range.InsertAfter (Cells(8, 4).Text)
objDoc.Bookmarks("SETOFF_AMOUNT_0").Range.InsertAfter (Cells(45, 4).Text)
objDoc.Bookmarks("SETOFF_AMOUNT_1").Range.InsertAfter (Cells(45, 4).Text)
objDoc.Bookmarks("SETOFF_AMOUNT_2").Range.InsertAfter (Cells(45, 4).Text)
objDoc.Bookmarks("SETOFF_WITH_WORDS_ENG").Range.InsertAfter (Cells(45, 5).Value)
objDoc.Bookmarks("SETOFF_WITH_WORDS_RU").Range.InsertAfter (Cells(45, 7).Value)
objDoc.Bookmarks("SETOFF_Cents").Range.InsertAfter (Cells(45, 6).Value)
objDoc.Bookmarks("SETOFF_Cents_1").Range.InsertAfter (Cells(45, 6).Value)
objDoc.Bookmarks("Balance_AMOUNT").Range.InsertAfter (Cells(7, 13).Text)
objDoc.Bookmarks("Balance_VAT_AMOUNT").Range.InsertAfter (Cells(7, 15).Text)
objDoc.Bookmarks("INVOICE_AMOUNT_FOR_THE_NEXT_SETOFF_1").Range.InsertAfter (Cells(46, 4).Text)
objDoc.Bookmarks("INVOICE_AMOUNT_FOR_THE_NEXT_SETOFF_2").Range.InsertAfter (Cells(46, 4).Text)
objDoc.Bookmarks("INVOICE_Number_FOR_THE_NEXT_SETOFF_1").Range.InsertAfter (Cells(46, 2).Value)
objDoc.Bookmarks("INVOICE_Number_FOR_THE_NEXT_SETOFF_2").Range.InsertAfter (Cells(46, 2).Value)
objDoc.Bookmarks("INVOICE_date_FOR_THE_NEXT_SETOFF_1").Range.InsertAfter (Cells(46, 3).Value)
objDoc.Bookmarks("INVOICE_date_FOR_THE_NEXT_SETOFF_2").Range.InsertAfter (Cells(46, 3).Value)
objDoc.Bookmarks("FOR_THE_NEXT_SETOFF_WITH_WORDS_ENG").Range.InsertAfter (Cells(46, 5).Value)
objDoc.Bookmarks("FOR_THE_NEXT_SETOFF_WITH_WORDS_RU").Range.InsertAfter (Cells(46, 7).Value)
objDoc.Bookmarks("INVOICE_FOR_THE_NEXT_SETOFF_Cents_1").Range.InsertAfter (Cells(46, 6).Value)
objDoc.Bookmarks("INVOICE_FOR_THE_NEXT_SETOFF_Cents_2").Range.InsertAfter (Cells(46, 6).Value)
objDoc.Bookmarks("CONTRACT_1").Range.InsertAfter (Cells(3, 2).Value)
objDoc.Bookmarks("CONTRACT_1_1").Range.InsertAfter (Cells(3, 2).Value)
objDoc.Bookmarks("ACT_DATE_1").Range.InsertAfter (Cells(3, 3).Value)
objDoc.Bookmarks("ACT_DATE_1_1").Range.InsertAfter (Cells(3, 3).Value)
objDoc.Bookmarks("ACT_AMOUNT_1").Range.InsertAfter (Cells(3, 4).Text)
objDoc.Bookmarks("ACT_AMOUNT_1_1").Range.InsertAfter (Cells(3, 4).Text)
objDoc.Bookmarks("ACT_AMOUNT_WITH_WORDS_ENG_1").Range.InsertAfter (Cells(3, 5).Value)
objDoc.Bookmarks("ACT_AMOUNT_WITH_WORDS_RU_1").Range.InsertAfter (Cells(3, 7).Value)
objDoc.Bookmarks("Cents_1").Range.InsertAfter (Cells(3, 6).Value)
objDoc.Bookmarks("Cents_1_1").Range.InsertAfter (Cells(3, 6).Value)
objDoc.Bookmarks("CONTRACT_2").Range.InsertAfter (Cells(4, 2).Value)
objDoc.Bookmarks("CONTRACT_2_2").Range.InsertAfter (Cells(4, 2).Value)
objDoc.Bookmarks("ACT_DATE_2").Range.InsertAfter (Cells(4, 3).Value)
objDoc.Bookmarks("ACT_DATE_2_2").Range.InsertAfter (Cells(4, 3).Value)
objDoc.Bookmarks("ACT_AMOUNT_2").Range.InsertAfter (Cells(4, 4).Text)
objDoc.Bookmarks("ACT_AMOUNT_2_2").Range.InsertAfter (Cells(4, 4).Text)
objDoc.Bookmarks("ACT_AMOUNT_WITH_WORDS_ENG_2").Range.InsertAfter (Cells(4, 5).Value)
objDoc.Bookmarks("ACT_AMOUNT_WITH_WORDS_RU_2").Range.InsertAfter (Cells(4, 7).Value)
objDoc.Bookmarks("Cents_2").Range.InsertAfter (Cells(4, 6).Value)
objDoc.Bookmarks("Cents_2_2").Range.InsertAfter (Cells(4, 6).Value)
objWord.ActiveDocument.SaveAs _
Filename:=FileNew, _
FileFormat:=wdFormatDocument, _
Password:="", _
AddToRecentFiles:=True, _
WritePassword:="", _
ReadOnlyRecommended:=False
objWord.Quit
End Sub
|
|