Opening and editting MS word documents in VB6

  • Thread starter http://www.visual-basic-data-mining.net/forum
  • Start date
H

http://www.visual-basic-data-mining.net/forum

I recently found this function for vb.net and was wondering if anyone knew
if this was possible in VB6:

Public Sub boldToHTML(ByVal doc As Word.Document)
With doc.Content.Find
.ClearFormatting()
.Font.Bold = 1
.Replacement.ClearFormatting()
.Replacement.Font.Bold = 0
.Text = "*"
.Execute(findtext:="", _
ReplaceWith:="<b>^&</b>", _
Format:=True, _
Replace:=Word.WdReplace.wdReplaceAll)
End With
End Sub

the function allows you to open a word document and using its find and
replace function change the content?

Any help would be great, thanks
 
H

Helmut Weber

Hi,
like this:
Sub Test3444()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
Resetsearch
With rDcm.Find
.Text = ""
.Font.Bold = True
.Replacement.Text = "<b>^&</b>"
.Replacement.Font.Bold = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
Resetsearch
End Sub
'---
Sub Resetsearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub
I think you could turn this into a sub, that
takes a doc as argument, easily, and put the
name of your word object in the appropriate places.
BTW, deformatting paragraph marks beforehand
might be a good idea.
 

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