+ Reply to Thread
Results 1 to 5 of 5

Can I add code to ThisWorkbook module with VBA extensibility?

  1. #1
    mikeb
    Guest

    Can I add code to ThisWorkbook module with VBA extensibility?

    I need to copy some event procedures from one Thisworkbook module to another
    Thisworkbook module, I have some code but it crashes Excel, can someone tell
    what I'm doing wrong?

    filename1 = ThisWorkbook.Path & "\tempmoditerate.bas"
    filename2 = ThisWorkbook.Path & "\tempmodrunsfgcalcs.bas"
    filename3 = ThisWorkbook.Path & "\tempmodsfcalcs.bas"
    filename4 = ThisWorkbook.Path & "\tempmain.bas"

    ThisWorkbook.VBProject.vbcomponents("modIterate").Export filename1
    ThisWorkbook.VBProject.vbcomponents("runsfgcalcs").Export filename2
    ThisWorkbook.VBProject.vbcomponents("sfcalcs").Export filename3
    ThisWorkbook.VBProject.vbcomponents("ThisWorkbook").Export filename4

    Set vbp = ActiveWorkbook.VBProject
    On Error Resume Next
    With vbp.vbcomponents
    .Remove vbp.vbcomponents("moditerate")
    .Import filename1
    .Remove vbp.vbcomponents("runsfgcalcs")
    .Import filename2
    .Remove vbp.vbcomponents("sfcalcs")
    .Import filename3
    Lines = vbp.vbcomponents("thisworkbook").CodeModule.countoflines
    vbp.vbcomponents("thisworkbook").CodeModule.deletelines 1, Lines
    vbp.vbcomponents("thisworkbook").CodeModule.addfromfile filename4
    vbp.vbcomponents("thisworkbook").CodeModule.deletelines 1, 4
    End With

    Kill filename1
    Kill filename2
    Kill filename3
    Kill filename4


  2. #2
    Gazeta
    Guest

    Re: Can I add code to ThisWorkbook module with VBA extensibility?


    Użytkownik "mikeb" <[email protected]> napisał w wiadomości
    news:[email protected]...
    > I need to copy some event procedures from one Thisworkbook module to

    another
    > Thisworkbook module, I have some code but it crashes Excel, can someone

    tell
    > what I'm doing wrong?
    >
    > filename1 = ThisWorkbook.Path & "\tempmoditerate.bas"
    > filename2 = ThisWorkbook.Path & "\tempmodrunsfgcalcs.bas"
    > filename3 = ThisWorkbook.Path & "\tempmodsfcalcs.bas"
    > filename4 = ThisWorkbook.Path & "\tempmain.bas"
    >
    > ThisWorkbook.VBProject.vbcomponents("modIterate").Export filename1
    > ThisWorkbook.VBProject.vbcomponents("runsfgcalcs").Export filename2
    > ThisWorkbook.VBProject.vbcomponents("sfcalcs").Export filename3
    > ThisWorkbook.VBProject.vbcomponents("ThisWorkbook").Export filename4
    >
    > Set vbp = ActiveWorkbook.VBProject
    > On Error Resume Next
    > With vbp.vbcomponents
    > .Remove vbp.vbcomponents("moditerate")
    > .Import filename1
    > .Remove vbp.vbcomponents("runsfgcalcs")
    > .Import filename2
    > .Remove vbp.vbcomponents("sfcalcs")
    > .Import filename3
    > Lines = vbp.vbcomponents("thisworkbook").CodeModule.countoflines
    > vbp.vbcomponents("thisworkbook").CodeModule.deletelines 1, Lines
    > vbp.vbcomponents("thisworkbook").CodeModule.addfromfile filename4
    > vbp.vbcomponents("thisworkbook").CodeModule.deletelines 1, 4
    > End With
    >
    > Kill filename1
    > Kill filename2
    > Kill filename3
    > Kill filename4
    >

    try to look here:
    http://www.cpearson.com/excel/vbe.htm
    mcg



  3. #3
    Doug Glancy
    Guest

    Re: Can I add code to ThisWorkbook module with VBA extensibility?

    mikeb,

    I tried this on one machine yesterday that had Norton Antivirus and it
    caused a problem because it thought the workbook with this code had a virus
    "mikeb" <[email protected]> wrote in message
    news:[email protected]...
    >I need to copy some event procedures from one Thisworkbook module to
    >another
    > Thisworkbook module, I have some code but it crashes Excel, can someone
    > tell
    > what I'm doing wrong?
    >
    > filename1 = ThisWorkbook.Path & "\tempmoditerate.bas"
    > filename2 = ThisWorkbook.Path & "\tempmodrunsfgcalcs.bas"
    > filename3 = ThisWorkbook.Path & "\tempmodsfcalcs.bas"
    > filename4 = ThisWorkbook.Path & "\tempmain.bas"
    >
    > ThisWorkbook.VBProject.vbcomponents("modIterate").Export filename1
    > ThisWorkbook.VBProject.vbcomponents("runsfgcalcs").Export filename2
    > ThisWorkbook.VBProject.vbcomponents("sfcalcs").Export filename3
    > ThisWorkbook.VBProject.vbcomponents("ThisWorkbook").Export filename4
    >
    > Set vbp = ActiveWorkbook.VBProject
    > On Error Resume Next
    > With vbp.vbcomponents
    > .Remove vbp.vbcomponents("moditerate")
    > .Import filename1
    > .Remove vbp.vbcomponents("runsfgcalcs")
    > .Import filename2
    > .Remove vbp.vbcomponents("sfcalcs")
    > .Import filename3
    > Lines = vbp.vbcomponents("thisworkbook").CodeModule.countoflines
    > vbp.vbcomponents("thisworkbook").CodeModule.deletelines 1, Lines
    > vbp.vbcomponents("thisworkbook").CodeModule.addfromfile filename4
    > vbp.vbcomponents("thisworkbook").CodeModule.deletelines 1, 4
    > End With
    >
    > Kill filename1
    > Kill filename2
    > Kill filename3
    > Kill filename4
    >




  4. #4
    Doug Glancy
    Guest

    Re: Can I add code to ThisWorkbook module with VBA extensibility?

    (woops)

    mikeb,

    I tried this on one machine yesterday that had Symantec Antivirus and it
    caused a problem because it thought the workbook with this code had a virus
    called "Bloodhound.ExcelMacro." When I tried it on another machine, it ran,
    although I only had the export Filename4 lines.

    hth,

    Doug

    "mikeb" <[email protected]> wrote in message
    news:[email protected]...
    >I need to copy some event procedures from one Thisworkbook module to
    >another
    > Thisworkbook module, I have some code but it crashes Excel, can someone
    > tell
    > what I'm doing wrong?
    >
    > filename1 = ThisWorkbook.Path & "\tempmoditerate.bas"
    > filename2 = ThisWorkbook.Path & "\tempmodrunsfgcalcs.bas"
    > filename3 = ThisWorkbook.Path & "\tempmodsfcalcs.bas"
    > filename4 = ThisWorkbook.Path & "\tempmain.bas"
    >
    > ThisWorkbook.VBProject.vbcomponents("modIterate").Export filename1
    > ThisWorkbook.VBProject.vbcomponents("runsfgcalcs").Export filename2
    > ThisWorkbook.VBProject.vbcomponents("sfcalcs").Export filename3
    > ThisWorkbook.VBProject.vbcomponents("ThisWorkbook").Export filename4
    >
    > Set vbp = ActiveWorkbook.VBProject
    > On Error Resume Next
    > With vbp.vbcomponents
    > .Remove vbp.vbcomponents("moditerate")
    > .Import filename1
    > .Remove vbp.vbcomponents("runsfgcalcs")
    > .Import filename2
    > .Remove vbp.vbcomponents("sfcalcs")
    > .Import filename3
    > Lines = vbp.vbcomponents("thisworkbook").CodeModule.countoflines
    > vbp.vbcomponents("thisworkbook").CodeModule.deletelines 1, Lines
    > vbp.vbcomponents("thisworkbook").CodeModule.addfromfile filename4
    > vbp.vbcomponents("thisworkbook").CodeModule.deletelines 1, 4
    > End With
    >
    > Kill filename1
    > Kill filename2
    > Kill filename3
    > Kill filename4
    >




  5. #5
    Yan-Hong Huang[MSFT]
    Guest

    RE: Can I add code to ThisWorkbook module with VBA extensibility?

    Hello Yaroguy,

    I am reviewing the issue thread. How is everything going? If the problem is
    still not resolved, please feel free to reply here and we will follow up.

    Thanks.

    Sincerely,
    Yanhong Huang
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.


+ 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