none
Agregar codigo al crear libro Excel desde VB.Net RRS feed

  • Pregunta

  • Estoy Haciendo una aplicacion que me genera un archivo de excel. Funciona perfectamente, pero necesito agregarle codigo vba para que al darle doble click a una celda dentro de un rango esta se marque. Inserte el siguiente codigo, no me genera errores pero tampoco me ingresa el codigo dentro de la hoja de excel.

    Dim oModule

    oModule = oBook.VBProject.VBComponents.Add(Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_StdModule)

    Dim sCode As String = "Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean" & Environment.NewLine
            sCode = sCode & "If Target.Count > 1 Then Exit Sub " & Environment.NewLine
            sCode = sCode & "If Intersect(Target, Range(""myChecks"")) Is Nothing Then Exit Sub " & Environment.NewLine
            sCode = sCode & "Target.Font.Name = ""marlett"" " & Environment.NewLine
            sCode = sCode & "If Target.Value <> ""a"" Then " & Environment.NewLine
            sCode = sCode & "Target.Value = ""a"" " & Environment.NewLine
            sCode = sCode & "Cancel = True " & Environment.NewLine
            sCode = sCode & "Exit Sub " & Environment.NewLine
            sCode = sCode & "End If " & Environment.NewLine
            sCode = sCode & "If Target.Value = ""a"" Then " & Environment.NewLine
            sCode = sCode & "Target.ClearContents " & Environment.NewLine
            sCode = sCode & "Cancel = True " & Environment.NewLine
            sCode = sCode & "Exit Sub " & Environment.NewLine

            sCode = sCode & "End If " & Environment.NewLine

            sCode = sCode & "End Sub"

            oModule.CodeModule.AddFromString(sCode)

    Alguien sabe o ha realizado algun proyecto similar..?

    martes, 27 de marzo de 2012 22:01