making a cell the same size as the picture

B

Bruce Baker

H

I'm opening an HTML page in word. It renders beautifully with the exception of a table which has a .gif in a cell. There is a white band around 3 of the 4 edges. I assume it is due to some sort of padding. How do I make the cell the same size as the image

Thank
Bruce
 
P

Peter Hewett

Hi Bruce

Try setting the cell padding to zero. This is a replacement for the last
macro I posted for you:

Sub UnlinkIncludepictureFields()
Dim rngStory As Word.Range
Dim lngIndex As Long

' Iterate through all story types
For Each rngStory In ActiveDocument.StoryRanges

Do Until rngStory Is Nothing

' Do this backwards as we are using the fields
' index and deleteing fields from the same collection at
' the same time
For lngIndex = rngStory.Fields.Count To 1 Step -1
With rngStory.Fields(lngIndex)
If .Type = wdFieldIncludePicture Then

' Remove cell padding if field is in a table
If .Result.Information(wdWithInTable) Then
With .Result.Cells(1)
.TopPadding = 0
.BottomPadding = 0
.LeftPadding = 0
.RightPadding = 0
End With

' Unlink the picture
.Unlink
End If
End If
End With
Next

' There may be linked stories so make sure we get them as well
Set rngStory = rngStory.NextStoryRange
Loop
Next
End Sub

This will only work if the picture is the highest item in the row as Word
scales the height of the for to fit the highest cell.

HTH + Cheers - Peter
 
P

Peter Hewett

Hi Bruce

I was just reviewing the code I posted before deleting it and I noticed
that I'd put one of the "End If"s in the wrong place. Please use this
version:

Sub UnlinkIncludepictureFields()
Dim rngStory As Word.Range
Dim lngIndex As Long

' Iterate through all story types
For Each rngStory In ActiveDocument.StoryRanges

Do Until rngStory Is Nothing

' Do this backwards as we are using the fields
' index and deleteing fields from the same collection at
' the same time
For lngIndex = rngStory.Fields.Count To 1 Step -1
With rngStory.Fields(lngIndex)
If .Type = wdFieldIncludePicture Then

' Remove cell padding if field is in a table
If .Result.Information(wdWithInTable) Then
With .Result.Cells(1)
.TopPadding = 0
.BottomPadding = 0
.LeftPadding = 0
.RightPadding = 0
End With
End If

' Unlink the picture
.Unlink
End If
End With
Next

' There may be linked stories so make sure we get them as well
Set rngStory = rngStory.NextStoryRange
Loop
Next
End Sub

Cheers - Peter
 

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