Can I do this using VBA in MS Frontpage?

D

Davy

I need a script that will examine a folder to discover all the files (jpg
images) in the folder and then create html that displays the images in my
current FrontPage web page . I can then move the images around on the page
and then save the page which will place the images in the web's images
folder.

If I do it manually using Insert/Picture etc then I get html which looks
like:

<p><img border="0" src="../../Data/LEASURE/Places/Newbury/DSC01160.JPG"
width="480" height="640">

I am puzzled that the drive and highest level folder which contains the
image is not shown.

I have only a little experience of VB and none of using VBA in FrontPage (if
VBA CAN be used in FrontPage)

any thoughts?

Davy
 
C

Chirag

Hi Davy,

The following VBA sub will do the job. Change the FolderName value to
something more appropriate for you.

---
Sub InsertImagesInActivePage()
Dim FolderName As String
Dim Path As String
Dim S As String
Dim FileName As String

FolderName = "C:\MyImages\"
Path = FolderName + "*.jpg"
S = ActiveDocument.body.innerHTML
FileName = Dir(Path, vbNormal)
Do While FileName <> ""
S = S + _
"<p><img src=""" + FolderName + FileName + """></p>" + _
vbCrLf
FileName = Dir()
Loop
ActiveDocument.body.innerHTML = S
End Sub
---

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 
D

Davy

Thanks Chirag - works a treat. You wouldn't believe how many newsgroups I
asked this in without an answer so I am grateful for your code.

many thanks

Davy
 

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