(Msg. 9) Posted: Tue Oct 13, 2009 11:25 am
Post subject: Re: Filename as caption [Login to view extended thread Info.] Archived from groups: microsoft>public>word>drawing>graphics (more info?)
On Oct 13, 2:22 pm, Chad Sowald <chadsow... DeleteThis @gmail.com> wrote:
> On Oct 12, 5:49 am, "Doug Robbins - Word MVP"
>
>
>
>
>
> <d... DeleteThis @REMOVECAPSmvps.org> wrote:
> > The following code will display a dialog in which you can select the folder
> > that contains the picture files and then it will insert each of the pictures
> > into a document with the filename of each following the picture
>
> > Dim myFile As String
> > Dim PathToUse As String
> > Dim myDoc As Document
> > Dim myrange As Range
> > 'Select the folder that contains the files
> > With Dialogs(wdDialogCopyFile)
> > If .Display <> 0 Then
> > PathToUse = .Directory
> > Else
> > MsgBox "Cancelled by User"
> > Exit Sub
> > End If
> > End With
> > 'Close all open documents before beginning
> > Documents.Close SaveChanges:=wdPromptToSaveChanges
> > 'Get the new title to be used for each document
> > Documents.Add
> > myFile = Dir(PathToUse & "*.*")
> > While myFile <> ""
> > With ActiveDocument
> > Set myrange = .Range
> > myrange.Collapse wdCollapseEnd
> > .InlineShapes.AddPicture PathToUse & myFile, , , myrange
> > Set myrange = .Range
> > myrange.Collapse wdCollapseEnd
> > myrange.InsertAfter vbCr & myFile & vbCr
> > End With
> > myFile = Dir()
> > Wend
>
> > --
> > Hope this helps.
>
> > Please reply to the newsgroup unless you wish to avail yourself of my
> > services on a paid consulting basis.
>
> > Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
>
> > "David Williams" wrote in messagenews:20091011152213zzdave@gmail.com...
> > > Thanks Doug, that worked really well for me.
>
> > > How would I modify it so that it worked whilst inserting say 20 pictures
> > > at a time. When I try this code it only puts one caption at the bottom.
>
> > > Your help is appreciated, thanks
>
> > > Dave
>
> > > Doug Robbins - Word MVP wrote:
>
> > > Re: AutoCaption With the Filename of the Image
> > > 09-Jul-08
>
> > > I posted this for someone else the other day:
>
> > > Running the following macro will allow you to select the picture that you
> > > want to insert, then it inserts the picture and the name of the file after
> > > the picture in a paragraph that is center aligned:
>
> > > Dim txtPhotoPath as String
> > > With Dialogs(wdDialogInsertPicture)
> > > If .Show Then
> > > txtPhotoPath = WordBasic.FilenameInfo$(.Name, 0)
> > > End If
> > > Selection.InsertAfter vbCr & txtPhotoPath
> > > Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
> > > End With
>
> > > You could modify it so that it also inserted a Figure number.
>
> > > --
> > > Hope this helps.
>
> > > Please reply to the newsgroup unless you wish to avail yourself of my
> > > services on a paid consulting basis.
>
> > > Doug Robbins - Word MVP
>
> > > "David" <Da... DeleteThis @discussions.microsoft.com> wrote in message
> > >news:B86493C0-452E-4BE3-9442-407A2C2B2485@microsoft.com...
>
> > > EggHeadCafe - Software Developer Portal of Choice
> > > Book Review: C# 3.0 Cookbook [O'Reilly]
> > >http://www.eggheadcafe.com/tutorials/aspnet/59386eb3-3049-46a7-8f07-6....
>
> Hi Doug. I get an error on the line: myFile = Dir(PathToUse &
> "*.*") with an error message of "Bad file name or number"..
>
> Do you know what would be wrong? I haven't modified your code at all.
Hey Doug. Nevermind, turns out the file path was too long. I moved
the images to another directory (closer to the root) and it worked
great. Thanks!
All times are: Eastern Time (US & Canada) (change) Goto page Previous1, 2
Page 2 of 2
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum