+ Reply to Thread
Results 1 to 3 of 3

Moving a sheet module from one workbook to another

Hybrid View

  1. #1
    Registered User
    Join Date
    02-06-2009
    Location
    Chattanooga, TN
    MS-Off Ver
    Excel 2007
    Posts
    46

    Moving a sheet module from one workbook to another

    I have written a macro to format a spreadsheet and then copy the formatted information into a new spreadsheet and close the original spreadsheet. The problem I have is that I have some code written to highlight a row a certain color based on a data validation list. I need to get that code into the new sheet so that it will work after the macro is closed.
    Here is the code I have found/put together to try and move the module. It adds the module as a class module instead of a sheet module.

    Sub CopyModule()
    
    Dim FName As String
    With Workbooks("NewCCPFormatSuspenseUpdate.xlsm")
    FName = .Path & "code.txt"
    .VBProject.VBComponents("FSuspense").Export FName
    End With
    Workbooks("Book1").VBProject.VBComponents.Import FName
    End Sub
    Here is the code I am trying to move:
    Private Sub Worksheet_Change(ByVal Target As Range)
        With Target
            If .Count > 1 Then Exit Sub
            If .Column <> 25 Then Exit Sub
            
            Select Case .Value
                'Green
                Case "Backup in Account Folder", "Backup in EDS"
                    .EntireRow.Interior.ColorIndex = 43
                'Purple
                Case "Paid", "Transfer in Process"
                    .EntireRow.Interior.ColorIndex = 39
                'Blue
                Case "Need Prior Bill’s Info/Backup", "Need Backup-File Doesn’t Match"
                    .EntireRow.Interior.ColorIndex = 41
                'Tan
                Case "Admin Services-Request Elec B/U", "Admin Services-Format Elec B/U", "Admin Services-Need Backup-Missing/No Info"
                    .EntireRow.Interior.ColorIndex = 40
                'Yellow
                Case "Due Date Error", "Greater than 20% Disc", "Working with BC", "No Outstanding Bill"
                    .EntireRow.Interior.ColorIndex = 27
                'Grey
                Case "Holding for Additional Files/Prem"
                    .EntireRow.Interior.ColorIndex = 16
                'Orange
                Case "BC to Clear"
                    .EntireRow.Interior.ColorIndex = 45
                    
                    End Select
        End With
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Moving a sheet module from one workbook to another

    Export it to a .bas rather than .txt

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Moving a sheet module from one workbook to another

    You could just copy the sheet and have it as the basis for your new workbook.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1