Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I would like to comment the lines who contains Msg Box from another code VBA. I'm trying this with the Library VBA EXTENSIBILITY but i doesn't found the solution.

Any help is welcome.

This is my code:

Sub CommentCode()
        Dim VBProj As VBIDE.VBProject
        Dim VBComp As VBIDE.VBComponent
        Dim CodeMod As VBIDE.CodeModule
        Dim LineNum As Long
        Const QUOTE = ' 

        Set VBProj = ActiveWorkbook.VBProject
        Set VBComp = VBProj.VBComponents("ThisWorkbook")
        Set CodeMod = VBComp.CodeModule

        With CodeMod
            LineNum = .CreateEventProc("Open", "Workbook")
            LineNum = LineNum + 1
            .InsertLines LineNum,  QUOTE 
        End With
    End Sub
share|improve this question
please, show the code snippet which you already have – KazJaw 16 hours ago

1 Answer

first, please change

Const QUOTE = '

to this:

Const QUOTE = "'"

basically your quote (or Rem) would be a string and needs to be enclosed in quotes.

as for the VB Extensibilty, you may need to delete the line once found, and insert a new line with the comment at the beginning.

See Chip Pearson: Programming in the VBA Editor

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.