+ Reply to Thread
Results 1 to 4 of 4

VBA adding a cls module to another workbook

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-30-2014
    Location
    London, England
    MS-Off Ver
    365 & 2010
    Posts
    107

    Question VBA adding a cls module to another workbook

    Hello you wonderful people.

    I am trying to create a module that will add a worksheet change event in another workbook and it is driving me completely insane and I am unsure what I am missing as it works one moment and then doesn't at all.

    Code is below.

    Sub Clean_Export()
        Dim wb, WB2 As Workbook
        Dim UB As Worksheet
        
        Set wb = ThisWorkbook
        Set UB = wb.Worksheets("UB")
    
    
        Workbooks.Add
        
        Set WB2 = ActiveWorkbook
        
        UB.Cells(1, 1).CurrentRegion.Copy
        WB2.Sheets(1).Paste
            
        With WB2.VBProject.VBComponents("Sheet1").CodeModule
        .DeleteLines StartLine:=1, Count:=.CountOfLines
        .AddFromFile "\\myfiles\Sheet1.cls"
        End With
    
        WB2.SaveAs Filename:="\\somewherespecial\RBC Unbilled Report\Unbilled Report - " & Format(Date, "dd mmm yyyy") & " - " & _
            Format(Time, "HH.MM") & ".xlsb", FileFormat:=xlExcel12
        
        WB2.Close True
        
        End Sub

    When I F8 through the code I can see the event in the sheet1 object but when it is closed and I re-open it is not there.

    What am I missing?

  2. #2
    Forum Contributor
    Join Date
    06-30-2014
    Location
    London, England
    MS-Off Ver
    365 & 2010
    Posts
    107

    Re: VBA adding a cls module to another workbook

    I'm taking bits and pieces out and it is becoming apparent it doesn't like the paste as when I remove it seems to be working?

  3. #3
    Forum Contributor
    Join Date
    06-30-2014
    Location
    London, England
    MS-Off Ver
    365 & 2010
    Posts
    107

    Re: VBA adding a cls module to another workbook

    Which is irrelevant as I need to paste the info in to the new workbook

  4. #4
    Forum Contributor
    Join Date
    06-30-2014
    Location
    London, England
    MS-Off Ver
    365 & 2010
    Posts
    107

    Re: VBA adding a cls module to another workbook

    I think I solved it.

    If anyone is interested I ended up saving the file at the beginning and then instead of using

    WB2.Close True
    at the end I ended up using

    WB2.Save
    WB2.Close False

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Save as active workbook with module & macro code in (this workbook)
    By nisshaheen76 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-07-2019, 10:24 AM
  2. [SOLVED] Can't reference ThisWorkbook from a module in another workbook module
    By Bukovnik in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-11-2015, 11:32 AM
  3. Compile error in hidden module: Module 1 when workbook opened on different machine!?
    By MathUKTeacher in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-06-2015, 04:38 PM
  4. copy module and past module in new workbook
    By flunzy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-17-2013, 04:33 AM
  5. how to access Sheet module, normal module, Worbook module to type code
    By alibaba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2009, 07:51 AM
  6. [SOLVED] Run worksheet module code from workbook module?
    By keithb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2005, 12:05 AM
  7. adding a module to several different workbooks
    By uriel78 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-22-2005, 12:06 PM

Tags for this Thread

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