View Single Post
 
Old 02-03-2022, 09:18 PM
mathemagician44 mathemagician44 is offline Windows 11 Office 2019
Novice
 
Join Date: Jan 2022
Posts: 7
mathemagician44 is on a distinguished road
Default Using portions of a filename for a caption.

I found a great code posted by Macropod a couple years ago (https://www.msofficeforums.com/word-...-pictures.html). I do thank you again for posting that code. I am essentially trying to take the following lines to grab only a portion of the file name:

Code:
'Get the Image name for the Caption
        StrTxt = Split(.SelectedItems(j), "\")(UBound(Split(.SelectedItems(j), "\")))
        StrTxt = " - " & Split(StrTxt, ".")(0)
'Insert the Caption on the row below the picture
        With oTbl.Cell(r + 1, c).Range
          .InsertBefore vbCr
          .Characters.First.InsertCaption _
          Label:="Photograph", Title:=StrTxt, _
          Position:=wdCaptionPositionBelow, ExcludeLabel:=False
          .Characters.First = vbNullString
          .Characters.Last.Previous = vbNullString
This is grabbing the entire filename until the first period in the file name. Since my filenames may be multiple sentences and the statement needs to end in a period, how can I change that above code to include everything but the file extension ".jpg"

After I get that figured out, I then need to make the caption not include the first entry of the file name. I.e., I number each photo so they are inserted in the correct order, but I don't want that number included in the caption.

My filenames for each jpg might be something like:
1 Dog is brown. Dog is big.
1.2 Cat is black. Cat is little.
2 Pencil is a yellow. Pencils are great.

I just want the macro to grab everything after the initial number in the file name, minus the ending file extension. Can this be done? I thank you for reading. Have a good day!

Last edited by macropod; 03-07-2022 at 07:37 PM. Reason: Added code tags & link to source code
Reply With Quote