Solved

Inserting simple word document with hyperlinks into html code -

Posted on 2003-11-20
1
394 Views
Last Modified: 2010-05-01
I have written a stock trading software system that produces a bunch of data that we are sending to our subscribers each week via an html newsletter. I have been able to create the newsletter html for all the data taken from my access database. Now I need to be able to read MS-Word docs, convert them to html and insert the html into specific sections of the newsletter html. Thanks to this forum, I have found code that converts (see below) the very simple Word documents into a fairly clean html file. I have one problem left to solve: How do I test for hyperlinks and how do I create the html code for those hyperlinks. (Confession: I am a pretty good VB programmer; I am a total newbie for html). Any/all help is appreciated.

 Dim docSource As Word.Document
  Dim lCharacterCntr As Long
 
  Dim strChar As String * 1
  Dim strHTMLFile As String
 
  Dim bBold As Boolean
  Dim bItalic As Boolean
  Dim bLink As Boolean
  Dim intIndentLevel As Integer
 
  Set docSource = Word.Documents.Open("C:\test.doc", , True)
 
  bBold = False
  bItalic = False
  bLink = False
  intIndentLevel = 0

  strHTMLFile = "test1.html"
  Open strHTMLFile For Output As #1

  ' create the document with basic header stuff
  Print #1, "<HTML>"
  Print #1, "<HEAD>"
  Print #1, "<TITLE>";
  Print #1, docSource.Name;
  Print #1, "</TITLE>"
  Print #1, "</HEAD>"
  Print #1, ""
  Print #1, "<BODY>"
 
  For lCharacterCntr = 1 To docSource.Characters.Count
    strChar = docSource.Characters(lCharacterCntr)
    If docSource.Characters(lCharacterCntr).Bold Then
      If Not bBold Then
         ' starting a bolded area
         Print #1, "<B>";
         bBold = True
      End If
    Else
      If bBold Then
         ' ending a bolded area
         Print #1, "</B>";
         bBold = False
      End If
    End If
   
    If docSource.Characters(lCharacterCntr).Italic Then
      If Not bItalic Then
         ' starting an Italic area
         Print #1, "<I>";
         bItalic = True
      End If
    Else
      If bItalic Then
         ' ending an Italic area
         Print #1, "</I>";
         bItalic = False
      End If
    End If
   
    If strChar = vbCr Then
      Print #1, "<P>"
    ElseIf strChar = vbLf Then
      Debug.Print "LF";
    Else
      Print #1, strChar;
    End If
  Next lCharacterCntr
  docSource.Close
  Set docSource = Nothing
 
  Print #1, "</BODY>"
  Print #1, "</HTML>"
  Close #1
0
Comment
Question by:turnermike
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 7

Accepted Solution

by:
wsteegmans earned 500 total points
ID: 9795532
First maybe some remarks ...

> I have found code that converts (see below) the very simple Word documents into a fairly clean html file.
Indeed, but your script can't handle:
- pictures
- bullet lists
- Tables
- Horizontal lines
- Headers and other Styles
- ...

If your word-docs are just plain text, it will work. Otherwise, I should use just the Save As HTML Functionlity. Indeed, the code is not so nice ... but is costs you NO time.

To answer your question:
In HTML, a URL is defined like this:
<A HREF="http://www.experts-exchange.com">IT Solutions Forum</A>

If you wan't to open the URL in a new window, it's like this:
<a href="http://www.hotmail.com" target="_blank">HoTMaiL</a>

Your Document Object (VBA) has a Hyperlinks Collection. In this collection, you find all the URL's defined in the document, with text and URL. Via the Range Object, you know where it is located ...

Maybe you can play with this objects ...

Just open your Word-document in Word, create a new procedure (in the Visual Basic Editor, for example something like this:
Sub Test
  MsgBox ActiveDocument.Hyperlinks.Item(1).TextToDisplay
End Sub
and 'Watch' the ActiveDocument, or just the Hyperlinks collection.

Success!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question