Using file name as the caption?

T

TerryK

Is it possible to use the name of the file (less the extension) that I am inserting as the caption

For Example if I drag an emf file with the name "(6e) Post Load Transfer.emf". I would like the caption to automatically be (6e) Post Load Transfer

Thanks for any input in advanc
TerryK
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?VGVycnlL?=,
Is it possible to use the name of the file (less the extension) that I am inserting as the caption?

For Example if I drag an emf file with the name "(6e) Post Load
Transfer.emf". I would like the caption to automatically be (6e) Post Load
Transfer.Something would likely be possible using a macro. But probably not with a
"drag and drop" technique. You'd need to use a dialog box for selecting the
macro to be inserted.

Which version of Word do you have?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
T

TerryK

Cindy,
I have both Word 2000 and 2002 available at my office. I can use which ever is better for this procedure in your judgement.
I am fairly proficient in VBA and macros in Excel but Word is not my forte.
Thanks for your help on this.

TerryK
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?VGVycnlL?=,
I have both Word 2000 and 2002 available at my office. I can use which
ever is better for this procedure in your judgement.
I am fairly proficient in VBA and macros in Excel but Word is not my forte.
The main difference in these two versions, for the approach I have in
mind, is that Word 2002 provides "FileDialog", making it possible to
display a dialog box and select multiple files, then process them.

Since you're comfortable with VBA I'm going to let you do a little
exploring on this part :) The same FileDialog is common to all Office XP
apps, including Excel. So look it up in the Excel VBA Help files and get a
feel for how it works. (I found it to be quite a bit of fun, when I
discovered it.)

What you need to retrieve is 1) the file path and 2) the file name(s) of
your selection. The examples will show you how this is done, you work
through the selections in a loop. The following bit of sample code will
show you how to insert the pictures one after the other at the end of the
current document.

Dim doc as Word.Document
Dim rng as Word.Range
Set doc = ActiveDocument
Set rng = doc.Range
rng.Collapse wdCollapseEnd

For Each vrtSelectedItem In .SelectedItems
doc.InlineShapes.AddPicture _
FileName:=vrtSelectedItem, _
Range:=rng
rng.MoveEnd wdCharacter, 2
rng.Collapse wdCollapseEnd
rng.MoveEnd wdCharacter, 1
rng.InsertCaption 'args you need here
rng.Collapse wdCollapseEnd
rng.InsertAfter vbCR
rng.Collapse wdCollapseEnd
Next vrtSelectedItem


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
T

TerryK

Thanks Cindy
This code is getting me where I want to go. I thought I had posted a thank you on Friday but looks like it did not get here. Just wanted to make sure you know that I appreciate your time and expertise
So far I have been able to extract the full path name as a caption but not just the file name. Apparently SelectedItems is a string and not an object. The only way I can think of to extract the file name from here is to search the string for / and delete text prior to that (have to loop the search for long path names). Then find the period and delete text past that
Thanks again

Terry
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?VGVycnlL?=,
So far I have been able to extract the full path name as a caption but
not just the file name. Apparently SelectedItems is a string and not an
object. The only way I can think of to extract the file name from here is
to search the string for / and delete text prior to that (have to loop the
search for long path names). Then find the period and delete text past
that.Depending on whether you're using a more recent version of Word you might
be able to use the InstrRev function to search the string "backwards" for
the position of the last \ and last period.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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