Solved

Inserting simple word document with hyperlinks into html code -

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

763 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