PDA

View Full Version : Inserting caption in table cell



jimmyk
08-28-2016, 05:30 AM
Hello,
I have a table with multiple rows. I am using the following code to select the cell in the next to the last row. With that cell selected, the following code works great to insert the image in that cell. The problem is that it inserts the caption UNDER the table and I would like to insert it in the cell under the image (the last row). Screenshot is attached.


Sub insertPicture()
Dim Doc As Dialog
Dim BClicked As String
Dim picPath As String
Dim picName As String

Set Doc = Dialogs(wdDialogInsertPicture)
With Doc
.Name = "*.jpg"
BClicked = .Show 'using show executes the dialog
picPath = .Name
End With
'strip off the path to get the file name
picName = Right(picPath, Len(picPath) - InStrRev(picPath, "\"))

'only do this if OK was clicked
If BClicked = -1 Then
Selection.InsertCaption Label:="Figure", _
TitleAutoText:="", Title:=": " & picName, _
Position:=wdCaptionPositionBelow
End If
End Sub

gmaxey
08-28-2016, 10:15 AM
Sub insertPicture()
Dim strName As String
Dim lngCol As Long
With Dialogs(wdDialogInsertPicture)
.Name = "*.jpg"
If .Show = -1 Then
lngCol = Selection.Range.Information(wdEndOfRangeColumnNumber)
strName = Right(.Name, Len(.Name) - InStrRev(.Name, "\"))
With Selection.Rows(1).Next.Cells(lngCol).Range
.InsertBefore vbCr
.Characters.First.InsertCaption Label:="Figure", _
TitleAutoText:="", Title:=": " & strName, _
Position:=wdCaptionPositionBelow
.Characters.First.Delete
.Characters.Last.Previous.Delete
End With
End If
End With
End Sub

jimmyk
08-28-2016, 11:03 AM
Thank you. Thank you. Perfect!!!

gmayor
08-28-2016, 08:22 PM
You might also like - http://www.gmayor.com/photo_gallery_template.html