Link to home
Start Free TrialLog in
Avatar of s_mccolgan
s_mccolgan

asked on

VB AddIn, Code to HTML

Greetings,
I have never worked with an add in before, so I will make this as simple as
possible.
Hopefully, you shall have enough knowledge and patience to guide me.

I am looking to build a very simple add in,
One that shall take the current code inside a VB Form and
save it with the following...
<html>
<head>
<title> Name of form </title>
</head>
<body>

<xmp> or <pre>

Code inside the Visual Basic Form

</xmp> or <pre>
</body>
</html>

Please guide me threw this process,
will only award full points if it works.

Thank you,
S. McColgan

Avatar of tomook
tomook

Piece of cake. Here is the module in question. If you would like the entire working project, send you email address.

Option Explicit

Public GlobalInstance As VBIDE.VBE  ' Initialize this in Connect.OnConnection

Sub ShowComponentCode(sComponentName As String, sHTMLText As String)

    Dim myComponent As VBComponent
    Dim myProj As VBProject
    Dim myCodeModule As CodeModule
    Dim myCodePane As CodePane
       
    Set myProj = GlobalInstance.ActiveVBProject
    sHTMLText = ""
   
    On Error Resume Next
    Set myComponent = myProj.VBComponents(sComponentName)
    If Err.Number <> 0 Then
        ' No component of this name.
        Exit Sub
    End If
   
    sHTMLText = "<html>" & vbCrLf & "<head>" & myComponent.Name & vbCrLf
    sHTMLText = sHTMLText & "</head>" & vbCrLf & "<body>" & vbCrLf & "<xmp>" & vbCrLf
   
    Set myCodeModule = myComponent.CodeModule
   
    sHTMLText = sHTMLText & myCodeModule.Lines(1, myCodeModule.CountOfLines) & vbCrLf
   
    sHTMLText = sHTMLText & "</xmp>" & vbCrLf
    sHTMLText = sHTMLText & "</body>" & vbCrLf
    sHTMLText = sHTMLText & "</html>" & vbCrLf
End Sub


Avatar of s_mccolgan

ASKER

tomook,
here is my email address
s_mccolgan@hotmail.com

if you do send the sample project, please answer this question with
"Check your email"
I will be more than happy to award the rightfull points.

ASKER CERTIFIED SOLUTION
Avatar of tomook
tomook

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial