+ Reply to Thread
Results 1 to 9 of 9

Add to HTML code using Excel userform

  1. #1
    Registered User
    Join Date
    10-25-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    28

    Add to HTML code using Excel userform

    Hello everyone,

    I have been working on an excel userform that takes input and generates some javascript code. I have been successful in outputting this code to a new .txt file with shell Notepad.

    I would like instead to add the text that the userform generates into an existing HTML document between the <script type = "text/javascript"> </script> tags at a specific line. I am not quite sure how I may be able to accomplish this.

    Private Sub CommandButton1_Click()

    Dim contNum As String
    /* I declared the string variables here to which I assigned the contentBox.value */

    Dim quote As String
    Dim filePath As String

    contNum = ContentNumber.Value
    /* I assigned the values here */

    filePath = "C:\Users\....\Debug Copy.html"
    quote = Chr(34)

    My initial code when I was creating a new txt file was
    Open "tempcode.txt" For Output As #1

    Print #1 ".... etc etc etc"

    Since I need instead to modify my own existing .html I have been rather lost on how I may do this. I have tried Open filePath For Append As #1 but it does not seem to be ok. I would appreciate any suggestions as I am rather new to VBA. Thank you!

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Add to HTML code using Excel userform

    Try code like this: you don't say how to determine what your specific line is, but this should give you an idea of how to make the new file - you can kill the old one and rename the new one, too....

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 08-06-2015 at 12:23 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    10-25-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    28

    Re: Add to HTML code using Excel userform

    Thank you for the reply! and sorry for not being detailed in how to determine where to place the generated code.

    I am trying to understand how your code functions. So the second free filenumber is an empty temp file that is populated by only "<script type = ""text/javascript"">" & contNum & "</script>" correct? Or was the existing file duplicated?
    The userform only generates a small portion of code that belongs in a line that perhaps I can have user specify. I hope I can keep the original code just add on to it. Can I maybe do something like this?

    *did not declare all variables
    Dim userVal As integer

    userVal = UserVal.Value

    Open "C:\Users\....\Debug Copy.html" For Input As #1
    strFinal = "</html>"

    While EOF(1) = False

    Line Input #1, strLine
    strFinal = strFinal + ModifyColumnUser(strLine)

    Wend
    strFinal = Left(strFinal, Len(strFinal) - (userVal - 1))

    Close #1

    after incorporating the file create that you showed? I am just trying to ask if it is viable. Thank you again!
    Last edited by Ray Storm; 08-06-2015 at 12:54 PM.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Add to HTML code using Excel userform

    Everything in the existing file is duplicated, except your placeholder is replaced with the value inserted.

    A better approach would be to have entries like this in your original file:

    <script type = "text/javascript">contNumGoesHere</script>
    ...
    <script type = "text/javascript">OtherInfoGoesHere</script>

    then use this in place of the original loop

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-25-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    28

    Re: Add to HTML code using Excel userform

    The userform is essentially adding a new object with its respective properties; thus each entry adds ~30 lines to the code between the <script> tags after some initialization code. That is why I think I need to specify where the code must be inserted. Thank you for the help; it is a great starting point!

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Add to HTML code using Excel userform

    Use the placeholder method - adding 30 lines is as easy as changing one word into 30 lines....

  7. #7
    Registered User
    Join Date
    10-25-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    28

    Re: Add to HTML code using Excel userform

    By placeholder method you mean how in your example you used the Replace (arg) to add in the contNum right?

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Add to HTML code using Excel userform

    Yes - for example, build up the string anyway you need

    Please Login or Register  to view this content.

    and then use this to place that where the text TablePlaceHolder appears in your file:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-25-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    28

    Re: Add to HTML code using Excel userform

    Thank you so much

+ 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. HTML code To Excel : Is it possible ?
    By chaitreya in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-09-2015, 12:01 AM
  2. Saving Excel (html code) to KML
    By NTB in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-26-2011, 02:58 PM
  3. userform webbrowser to preview HTML code.
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2009, 01:47 AM
  4. HTML code in excel
    By avanishjoshi in forum Excel General
    Replies: 1
    Last Post: 06-24-2009, 05:35 AM
  5. Excel as HTML code Generator
    By mightytomwhitey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-11-2009, 02:46 PM
  6. Import HTML code into Excel
    By josuegm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2006, 06:10 PM
  7. [SOLVED] html source code into Excel
    By pwwatson in forum Excel General
    Replies: 0
    Last Post: 09-04-2005, 09:05 PM

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