macro from MS Knowledge Base article won't run

T

Tony Logan

Actually it won't even display in my list of macros when I access the Macro dialog box, although in the VBE, I can see all the coding. When I try to run the macro from the VBE, nothing happens. I'm stumped as to what to try to troubleshoot

The article in question is "HOWTO: Programmatically Use the HTML Filter DLL to Save Word Documents as Plain HTML," at http://support.microsoft.com/default.aspx?scid=291325

I'm running Word 2000 on Windows NT 4.0

Below is the code in its entirety, directly from the article, without any modification on my part

Private Declare Function MSPeelerMain Lib "msfilter.dll"
(ByVal sHtmlFile As String, ByVal sCmdOptions As String) As Intege

' This is the output file for the example; change as needed
Private Const c_sOutputFile As String = "C:\MyNewHTMLFile.htm

Public Sub SaveAsSimpleHTML( sDocFile As String
Dim wdApp As Objec
Dim wdDoc As Objec

On Error GoTo Err_Routin

'Launch Microsoft Word and open a test document
Set wdApp = CreateObject("Word.Application"
Set wdDoc = wdApp.Documents.Open( sDocFile

' Save the test document as HTML (includes XML data islands)
wdDoc.SaveAs c_sOutputFile, 8 '(wdFormatHTML

'Close the test document and quit Microsoft Word
'NOTE: The document must be closed before the XML can be remove
'because Word maintains an exclusive file lock
wdDoc.Clos
wdApp.Qui

'Make sure Word has time to shut down properly
DoEvent

'If the filter is installed, remove the extra XML
MSPeelerMain c_sOutputFile, "-tfrb

MsgBox "The current file was saved as plain HTML." &
vbCrLf & "Location: " & c_sOutputFil

Exit Su

Err_Routine
If Err.Number = 53 The
' File not found would be if the DLL could not be found, whic
' would mean that the Filter is not installed on this computer
MsgBox "The HTML Filter 2.0 DLL is not installed.
Err.Clea
Resume Nex
Els
MsgBox "An error occurred: " & Str(Err.Number) &
" - " & Err.Description, vbCritica
End I
End Sub
 
T

Tom Winter

The only "routines" that show up in TOOLS | MACRO are SUBs with no
parameters. Think about it. Using TOOLS | MACRO, how would the user specify
the sDocFile parameter to this SaveAsSimpleHTML routine? Add another routine
like this:

Public Sub MySaveAsSimpleHTML()

SaveAsSimpleHTML "C:\PathToMyDocumentIWantToStrip.doc"

End Sub

Now MySaveAsSimpleHTML will show up in TOOLS | MACRO
--
Tom Winter
(e-mail address removed)
www.AmosFiveSix.com

Tony Logan said:
Actually it won't even display in my list of macros when I access the
Macro dialog box, although in the VBE, I can see all the coding. When I try
to run the macro from the VBE, nothing happens. I'm stumped as to what to
try to troubleshoot.
The article in question is "HOWTO: Programmatically Use the HTML Filter
DLL to Save Word Documents as Plain HTML," at
http://support.microsoft.com/default.aspx?scid=291325.
 
J

Jay Freedman

Actually, it's a bit more than that: The code from the KB article is for
Visual Basic 6.0, which is not quite the same as VBA. It contains these
statements that are going to cause trouble if you run them from inside VBA:

Rewritten as a purely VBA macro to process the current document, the code
looks like this:

Private Declare Function MSPeelerMain Lib "msfilter.dll" _
(ByVal sHtmlFile As String, ByVal sCmdOptions As String) As Integer

' This is the output file for the example; change as needed.
Private Const c_sOutputFile As String = "C:\MyNewHTMLFile.htm"

Public Sub SaveAsSimpleHTML()
Dim wdDoc As Document

On Error GoTo Err_Routine

' Use the current document.
Set wdDoc = ActiveDocument

' Save the test document as HTML (includes XML data islands).
wdDoc.SaveAs c_sOutputFile, 8 '(wdFormatHTML)

'Close the test document.
'NOTE: The document must be closed before the XML can be removed
'because Word maintains an exclusive file lock.
wdDoc.Close

'Make sure the doc has time to shut down properly.
DoEvents

'If the filter is installed, remove the extra XML.
MSPeelerMain c_sOutputFile, "-tfrb"

MsgBox "The current file was saved as plain HTML." & _
vbCrLf & "Location: " & c_sOutputFile

Exit Sub

Err_Routine:
If Err.Number = 53 Then
' File not found would be if the DLL could not be found, which
' would mean that the Filter is not installed on this computer.
MsgBox "The HTML Filter 2.0 DLL is not installed."
Err.Clear
Resume Next
Else
MsgBox "An error occurred: " & Str(Err.Number) & _
" - " & Err.Description, vbCritical
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top