help with document conversion

W

woody

I have a program that takes a letter written in word and
converts it to html using word. one of the goals of it is
to strip out headers, footers, and the inline shapes
collection.

I've got it doing most of what i want except when i'm done
i have the folder...(x)_Files with 2 entries, Header.htm
(totally blank) and of course the file list. So what am I
missing? this thing has driven me nuts.

I appreciate any and all guidance sincerely.

thanx

Woody
code below
___________________________________________________________


Private Sub cmdConvert_Click()
On Error Resume Next

Dim lenDocname As Integer
Dim intStart As Integer

Dim bolStarted As Boolean

Dim newDocName As String
Dim oldDocName As String
Dim strContents As String

Dim WordApp As Word.Application
Dim wordDoc As Word.Document
Dim noneDoc As Word.Document


Set noneDoc = Nothing

Set WordApp = GetObject(, "Word.Application")
If Err <> 0 Then
'word wasn't running, start it from code
Set WordApp = CreateObject("Word.Application")
End If

'get old document name
oldDocName = Trim(txtDoc.Text)
' get length
lenDocname = Len(Trim(oldDocName))
'remove last 4 characters and replace with .htm extension
newDocName = Left(Trim(oldDocName), lenDocname - 4)
& ".htm"
'delete new file just in case
strContents = txtPath.Text & newDocName
Kill (strContents)

'open and display document
strContents = txtPath.Text & oldDocName
Set wordDoc = Documents.Open(FileName:=strContents, _
ConfirmConversions:=False,
_
ReadOnly:=False, _
AddToRecentFiles:=False, _
Revert:=False, _
Format:=wdDocument, _
Visible:=True)
' no idea why but i always get err 53 file not found yet
the file still opens
If Err <> 0 And Err <> 53 Then
GoTo Quit_Conversion
End If

Err.Clear

' make it active
wordDoc.Activate
WordApp.ActiveWindow.ActivePane.Activate

'delete headers
WordApp.ActiveWindow.ActivePane.Activate

For intStart = 1 To 4 Step 1

Select Case intStart

Case Is = 1

With
wordDoc.ActiveWindow.ActivePane.View
.SeekView =
wdSeekCurrentPageHeader
If Err = 0 Then
Selection.WholeStory
Selection.Delete
Else
Err.Clear
End If

End With

Case Is = 2

With
wordDoc.ActiveWindow.ActivePane.View
.SeekView = wdSeekPrimaryHeader
If Err = 0 Then
Selection.WholeStory
Selection.Delete
Else
Err.Clear
End If

End With

Case Is = 3

With
wordDoc.ActiveWindow.ActivePane.View
.SeekView =
wdSeekEvenPagesHeader
If Err = 0 Then
Selection.WholeStory
Selection.Delete
Else
Err.Clear
End If

End With

Case Is = 4

With
wordDoc.ActiveWindow.ActivePane.View
.SeekView =
wdSeekFirstPageHeader
If Err = 0 Then
Selection.WholeStory
Selection.Delete
Else
Err.Clear
End If

End With

End Select

Next intStart

' remove external objects
' tried going forward but only caught teh first item
so start at the back
wordDoc.ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument
For intStart = ActiveDocument.InlineShapes.Count To 1
Step -1

wordDoc.InlineShapes.Item(intStart).Delete
If Err <> 0 Then
Err.Clear
End If

Next intStart

'delete endnotes
wordDoc.ActiveWindow.ActivePane.Activate

With wordDoc.ActiveWindow.ActivePane.View

.SeekView = wdSeekEndnotes

If Err = 0 Then
Selection.WholeStory
Selection.Delete
Else
Err.Clear
End If

End With

'delete footers
wordDoc.ActiveWindow.ActivePane.Activate

For intStart = 1 To 4 Step 1

Select Case intStart

Case Is = 1

With
wordDoc.ActiveWindow.ActivePane.View
.SeekView =
wdSeekCurrentPageFooter
If Err = 0 Then
Selection.WholeStory
Selection.Delete
Else
Err.Clear
End If

End With

Case Is = 2

With
wordDoc.ActiveWindow.ActivePane.View
.SeekView = wdSeekPrimaryFooter
If Err = 0 Then
Selection.WholeStory
Selection.Delete
Else
Err.Clear
End If

End With

Case Is = 3

With
wordDoc.ActiveWindow.ActivePane.View
.SeekView =
wdSeekEvenPagesFooter
If Err = 0 Then
Selection.WholeStory
Selection.Delete
Else
Err.Clear
End If

End With

Case Is = 4

With
wordDoc.ActiveWindow.ActivePane.View
.SeekView =
wdSeekFirstPageFooter
If Err = 0 Then
Selection.WholeStory
Selection.Delete
Else
Err.Clear
End If

End With

End Select

Next intStart

'save as html
wordDoc.SaveAs FileName:=txtPath.Text & newDocName, _
FileFormat:=wdFormatHTML, _
LockComments:=False, _
Password:="", _
AddToRecentFiles:=False, _
WritePassword:="", _
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, _
SaveFormsData:=False, _
SaveAsAOCELetter:=False

If Err <> 0 Then
GoTo Quit_Conversion
End If

txtDoc.Text = newDocName

cmdConvert.Enabled = False
cmdConvert.Visible = False

Display_Message "Document Converted successfully", "w"


Quit_Conversion:
If Err <> 0 Then
Display_Message Err.Number & " " & Err.DESCRIPTION
& ", " & Err.Source, "e"
End If

If wordDoc <> noneDoc Then
wordDoc.Close SaveChanges:=False
End If

Set wordDoc = Nothing

If bolStarted = True Then
WordApp.Quit
End If

Set WordApp = Nothing

End Sub

Private Sub Display_Message(StrMessage as string, StrLevel
as string)

msgbox strmessage & " " & strlevel

End sub
 
W

woody

When i do the deletes and save by hand i dont get the file
list or the document_Folders folder.makes me wonder if im
missing something programmatically that i do by hand?

It is bloated but its the easiest to invoke
programatically. I dont want to have to invent my own
html coder just so i can send a marketing email to
someone. I know its plain text, ive written enough of it,
but the devil is in the details, keeping fonts, spacing,
all the stuff that the folks in marketing like to put into
the emails. my job is just to get the stuff out there as
fast as possible. word is a lousy tool, but once the
document is created its stored and then dropped into email
HTML body. it stays essentially untouched by word or
about 3 months after that.
 
W

woody

When i do the deletes and save by hand i dont get the file
list or the document_Folders folder.makes me wonder if im
missing something programmatically that i do by hand?

It is bloated but its the easiest to invoke
programatically. I dont want to have to invent my own
html coder just so i can send a marketing email to
someone. I know its plain text, ive written enough of it,
but the devil is in the details, keeping fonts, spacing,
all the stuff that the folks in marketing like to put into
the emails. my job is just to get the stuff out there as
fast as possible. word is a lousy tool, but once the
document is created its stored and then dropped into email
HTML body. it stays essentially untouched by word or
about 3 months after that.
 

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