?
Solved

Inserting simple word document with hyperlinks into html code -

Posted on 2003-11-20
1
Medium Priority
?
398 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
1 Comment
 
LVL 7

Accepted Solution

by:
wsteegmans earned 1000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

839 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