Generate the corresponding Word document based on the contents of Excel and the Word template

Source: Internet
Author: User

SubSetName ()DimI as Integer    DimPspname as String    DimPspnumber as String    DimPath as String    DimSrcpath as String    DimSrcPath2 as String        DimWordApp as Object    DimWordDoc as Object    DimWordarange as Object    DimWordselection as Object    DimReplacesign as Boolean        DimSearch1 as String    DimSearch2 as String    DimDocprefix as String    DimDocsuffix as String    DimRangsize as Integer            'docprefix = "-PSP"    'docsuffix = "Purchase spec. doc"    'Search1 = "Wire"    'SEARCH2 = "6000397-PSP"    'rangsize =Docprefix="-tst"Docsuffix="incoming inspection specification. doc"Search1="High voltage power supply"SEARCH2="6000391-tst"rangsize= 1100 forI =4  to 5Srcpath="C:\cygwin\tmp\BOM\tst.doc"Path="D:\bom\"& ActiveSheet.Cells (I,3) &"-"& ActiveSheet.Cells (I,4) SrcPath2= Path &"\aa.doc"Pspname= Path &"\"& ActiveSheet.Cells (I,3) & Docprefix &" "& ActiveSheet.Cells (I,4) &Docsuffix Pspnumber= ActiveSheet.Cells (I,3) &DocprefixMkDir(PATH)FileCopySrcpath, srcPath2 Name srcPath2 asPspnameSetWordApp =CreateObject("Word.Application")'Create a Word instanceWordapp.visible =False                                         'block Word instance forms        SetWordDoc = WordApp.Documents.Open (pspname)'Open the file and give the file instance        SetWordselection = Wordapp.selection'Locating file Instances        SetWordarange = WordApp.ActiveDocument.Range (0, rangsize)'Specify file Edit locationWordarange.select'Activate edit Location                 Doreplacesign= WordArange.Find.Execute (Search1,True,,,,, wdReplaceAll, Wdfindcontinue,, ActiveSheet.Cells (I,4),True)        Loop UntilReplacesign =False                                DimRngstory as Object        DimLngjunk as Long         for  eachRngstoryinchworddoc.storyranges Doreplacesign= RngStory.Find.Execute (SEARCH2,True,,,,, wdReplaceAll, Wdfindcontinue,, Pspnumber,True)            SetRngstory =Rngstory.nextstoryrangeLoop UntilRngstory is  Nothing        NextWorddoc.save Worddoc.closeTrueWordapp.quitNextIEnd Sub

Generate the corresponding Word document based on the contents of Excel and the Word template

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.