PDA

View Full Version : Import Pics into word



vlad999
12-20-2006, 08:56 PM
Hi,

I have images in many sub directories and I just want to import one random image from each sub directory in to a word doc when the images are imported I would like to have them automatically resized and labled (based on the directory name).

Image Name (taken from the last folder name in the directory) the images are seperated by 2 tabs and images are resized to 5cm x 6.11cm

Image Name 1 Image Name 2
_____________ _____________
|xxxxxxxxxxxxx| |xxxxxxxxxxxxx |
|xxxxxxxxxxxxx| |xxxxxxxxxxxxx |
| xxxxIMG1xxx | |xxx IMG2xxxxx |
|xxxxxxxxxxxxx| |xxxxxxxxxxxxx |
Lxxxxxxxxxxxxx| Lxxxxxxxxxxxxxx|


So if it is possible to create a popup window that allows me to specify a directory then a macro to create magic then this would be very useful and save me heaps of time

Bilby
12-21-2006, 02:00 PM
The attachment does that. I can't remember where on the web I found it but I hope you have fun(?) with it.

fumei
12-21-2006, 02:28 PM
The attachment does that? Really? Hmmmm. It doesn't for me. It displays a folder picker.

It does not:

allow any selection of a file - as the OP asked
(it does not even allow you to SEE any files)
allow multiple selection of file (image) names - as the OP asked
insert text based on the folder name - as the OP asked
automatically resize - as the OP asked
automatically label - as the OP asked
automatically separate images by 2 tabs - as the OP asked

vlad999, this is not a trivial exercise. What have you tried so far? Have you tried recording a macro to do the graphic sizing and placement?

vlad999
12-21-2006, 02:34 PM
I have a maro to bring up the insert picture menu, that allows me to browse directories and select my picture then insert it. Then I have another macro that resizes the selected image. But the user still needs to name the image and select an image from each folder. Its the selecting just one image from a folder thats killing me because there are SO many folders and I waste like 20 minutes of my day doing this...I'm just looking to make life easier and more efficient.



allow multiple selection of file (image) names - as the OP asked
I did not ask for this...I think I just want the macro to select a rendom image from each sub folder in a directory. i.e I select one directory then the macro goes to each folder in the directory and if it comes across a directory with images then it selects a random image (or image number 1) and inserts it into the word doc with the sub folder name above the image.

Sorry I suck at explaining things

Have found a better code on this site for my two macros not I have just one step but still cant select random images

Option Explicit

Sub Logo()
Application.Dialogs(wdDialogInsertPicture).Show
Selection.WholeStory
Selection.InlineShapes(1).Height = 160
Selection.InlineShapes(1).Width = 170
End Sub

fumei
12-21-2006, 09:14 PM
allow multiple selection of file (image) names - as the OP asked
I did not ask for this...I think I just want the macro to select a rendom image from each sub folder in a directory.Sounds like multiple selection to me.

You have a folder. It has 6 sub folders. Assuming there are images in each, you ARE asking that 6 images be selected and processed. That is multiple.

Random images. Hmmmm. Here is my suggestion. Use FileSystemObject. In pseudo-code:

Give the FileSystemObject your seed folder.
Dim sFilename, sFolderName As String
For Each SubFolder in FSO.Folder
For Each File in SubFolder
sFolderName = SubFolder.Name
If File is image file Then
build array of image File names
End If
Next
use Rnd function to get randon number of the
array of image filename
sFileName = array(rnd) - this will be the file
Call Processing (sFolderName, sFileName)
Next



That way you process each folder with the Processing Sub.

The processing Sub will do the action of getting the image file and resizing. The Processing Sub should have the selected image file, and folder name, passed as parameters.

Sub Processing (sFolderName As String, _
sFileName As String)

vlad999
12-21-2006, 09:25 PM
Thanks for your help, but i'm a VBA noob and I dont really know how to fill in the blanks in your code. It doesnt have to be a random image it can just be the first image in the folder.

fumei
12-25-2006, 09:11 AM
First of all, look up how to use FileSystemObject. Unfortunately, Help is not helpful for this. You will need to search MSDN.

Second, as I stated, this is NOT trivial. You have two issues. Accessing each folder, and processing the image in the way you want.

I suggest you do these independently. Again, as I suggest, make a Sub with the processing instructions, then Call it for each subfolder.

As a start, get the processing procedure down. Use ONE folder and use Dir (not FileSysemObject). You can look up the use of Dir in Help. Have a test folder with, say, four images. Use Dir to process the four images in the way you want.

Once you have the processing instructions down properly, then build another procedure that does use FSO to work your way through multiple folders.

Question: in the real world of your folder structure, are there sub-sub-folders? If there are, it is going to get complicated looping through them. It certainly can be done, but you will have to iterate through each sub-folder (of the FileSystemObject) one by one.

But again, start with getting your processing instructions down.

This is not trivial, and is going to take some work on your part. At the end of of it though, you will for sure have a greater understanding of VBA and will not be a "noob".