Solved

Inserting simple word document with hyperlinks into html code -

Posted on 2003-11-20
1
393 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

738 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