VBA TIPS
Copying the code lines of ThisWorkbook to the new workbook

This program would copy the procedures in ThisWorkbook module to the ThisWorkbook module of the new workbook.

Please note, if you are using Excel 2002(XP) and the later, to run this program, you need to tick Trust access to Visual Basic Project from Tools > Macro > Security... from main menu.

Trust access to Visual Basic Project


Place the following in the standard module.

Option Explicit


Sub ThisWorkbookCodeLineToNewWb()
'// the code line of ThisWorkbook module Copy to New Workbook.
    Dim wbNew As Workbook, strRet As String
    Set wbNew = Workbooks.Add
    With ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
        strRet = .Lines(1, .CountOfLines)
    End With
    With wbNew.VBProject.VBComponents("ThisWorkbook").CodeModule
    .DeleteLines 1, .CountOfLines '//Delete Codes already wrriten
    .InsertLines 1, strRet '// Write Code
    End With
    Set wbNew = Nothing
    MsgBox "Done"
End Sub

| HOME |
Copyright © cellmasters.net - colo's junk room All Right Reserved
ABOUT
WORKS
THE CELL MASTERS
CONTACT
LINKS
Tips and Information about Microsoft Excel|Masaru Kaji aka Colo