Insert several html files into word

L

LMC

Hi,
Is there somebody who would have an answer to this problem?
I would like to insert automatically in a Word document several HTML files.
These files are in a network directory.
If I do this manually, I go to "Insert" then "Files", then look for HTML
files and finally Ok, then start again for a new one and so on ...
The code could be something like this (but I would like to take all the
*.htm files .):

Sub InsertHtml()

'

Selection.InsertFile FileName:="\\SERVER\Directory\Dir1\info.htm",
Range:="", _

ConfirmConversions:=False, Link:=False, Attachment:=False

End Sub

The user should also give the directory target where all the HTML files are.
Any help ?

Thanks in advance.

LMC
 
L

LMC

Have the solution:

Dim FSO As FileSystemObject
Dim fsoFldr As Folder
Dim fsoFile As File
Dim i As Long
Set FSO = New FileSystemObject
Set fsoFldr = FSO.GetFolder("C:\HTML_FILES")
For Each fsoFile In fsoFldr.Files
With ActiveDocument.Range
..InsertAfter fsoFile.Path
..Collapse 0
..InsertFile FileName:=fsoFile.Path, Range:="", ConfirmConversions _
:=False, Link:=False, Attachment:=False
..Collapse 0
End With
DoEvents
Next
Set fsoFile = Nothing
Set fsoFldr = Nothing
Set FSO = Nothing
-------
or a file format
-----

For Each fsoFile In fsoFldr.Files
'returns a 0 (false) if not found
If InStr(fsoFile.Name,".html") Then
With ActiveDocument.Range
..InsertAfter fsoFile.Path
..Collapse 0
..InsertFile FileName:=fsoFile.Path, Range:="", ConfirmConversions _
:=False, Link:=False, Attachment:=False
..Collapse 0
End With
DoEvents
End If
Next
-------------

You'll need to add a reference to the Scripting Runtime library in the
Tools -> References -> Microsoft Scripting Runtime

Thanks to Wamphyri from www.visualbasicforum.com
The question now is, how do I get and put information from user for the
directory name ...???
Thanks

LMC
 
J

JGM

Hi there LMC,

Try this:
'_______________________________________
Function GetPath() As String
'Needs a reference to (Tools > Reference)
'Microsoft Shell Controls And Automation

Dim oShell As Shell32.Shell
Dim oFolder As Shell32.Folder
Dim EverythingOK As Boolean

EverythingOK = False

Set oShell = New Shell32.Shell
Set oFolder = oShell.BrowseForFolder(0, "Select ", 0)

On Error GoTo NoPath
GetPath = oFolder.Self.Path
EverythingOK = True

NoPath:
Set oFolder = Nothing
Set oShell = Nothing

On Error GoTo 0
If EverythingOK Then Exit Function

MsgBox "Action cancelled by user.", vbExclamation, "Cancelled"
End Function
'_______________________________________

HTH
Cheers!
 
L

LMC

Hi,



Thanks for your answer.



Can you tell me how do I insert this code into the script and how do I put
the "GetPath = oFolder.Self.Path" into the "Set fsoFldr =
FSO.GetFolder("C:\HTML_FILES")"?



Thanks again



Regards



LMC
 
J

JGM

Hi LMC,

Just append the code at the end of your code,
and,
change

Set fsoFldr = FSO.GetFolder("C:\HTML_FILES")
to

Set fsoFldr = FSO.GetFolder(GetPath)

Cheers!
 

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