Excel VBA inserts VBA module code from this workbook in the worksheet that generated the copy

Source: Internet
Author: User
Tags save file

That is, add a worksheet to the workbook, and then move out of the workbook to a new workbook, and copy the code of one module of the workbook to the new workbook before moving out. Here is the key code:

        '======================================================================        'Each class list is saved as a single XLS fileActivesheet.moveChDirMyPath'Ignore dialog box, overwrite saveApplication.DisplayAlerts =False                'class name increase "examinee number Processing" VBA module        DimIcodelines as Integer        DimSCode as StringIcodelines= ThisWorkbook.VBProject.VBComponents ("each class exam number processing"). Codemodule.countoflines'get the number of lines of code in the moduleSCode = ThisWorkbook.VBProject.VBComponents ("each class exam number processing"). Codemodule.lines (1, Icodelines)'get the 1th to Icodelines line codeActiveWorkbook.VBProject.VBComponents.Add (vbext_ct_StdModule). Name="each class exam number processing" 'Add "class number Processing" module to the new fileActiveWorkbook.VBProject.VBComponents ("each class exam number processing"). Codemodule.addfromstring SCode'Add the "ThisWorkbook" module code to the ActiveWorkbook moduleActiveWorkbook.SaveAs Filename:=mypath &"\ Level 2017"& Dickey & Classteacher &". xls", Fileformat:=xlexcel8'save File as Version 2003 (XLEXCEL8) XLS fileActivewindow.close

Copy the "Class number processing" module to a new workbook

Original File Download

Excel VBA inserts VBA module code from this workbook in the worksheet that generated the copy

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.