-----Original Message-----
Hi, Laura,
In the template for your documents, turn off protection temporarily. In the
first cell of the first table, press Ctrl+F9 to get a pair of field braces,
and type this text (all in one line) inside the braces:
MacroButton InsertPictureInTable [Double-click here to insert picture]
Press F9 to update the field, and all that will be visible is the part in
square brackets. You can format this as you like, maybe in red so it stands
out.
Then open the VBA editor (Alt+F11). In the Project Explorer window, select
the name of your template, and use the Insert > Module menu item. Copy the
macro code below, and paste it into the blank editing window. Then close the
VBA editor, protect the template for forms, and save it. When you create a
new document from the template, you can double-click the text in the cell to
start the macro.
Option Explicit
Public Sub InsertPictureInTable()
Dim oTbl As Table, oCell As Cell
Dim oRg As Range
Dim ProtType As WdProtectionType
Dim RowHt As Single, ColWd As Single
Dim PicHt As Single, PicWd As Single
Dim ScaleFactor As Single
Dim PicFile As String
Dim oPic As InlineShape
Dim dlg As Dialog
' unprotect document if necessary
ProtType = ActiveDocument.ProtectionType
If ProtType <> wdNoProtection Then
ActiveDocument.Unprotect
End If
If ActiveDocument.Tables.Count = 0 Then
MsgBox "The table is missing!"
GoTo bye
End If
Set oTbl = ActiveDocument.Tables(1)
Set oCell = oTbl.Cell(Row:=1, Column:=1)
Set oRg = oCell.Range
' if the cell contains one or more
' fields, remove it/them
Do While oRg.Fields.Count > 0
oRg.Fields(1).Delete
Loop
' find cell size
RowHt = oCell.Height
ColWd = oCell.Width
' let user choose picture
Set dlg = Dialogs(wdDialogInsertPicture)
With dlg
If .Display = -1 Then
PicFile = .Name
Else
GoTo bye
End If
End With
' insert picture in cell
Set oPic = ActiveDocument.InlineShapes.AddPicture( _
FileName:=PicFile, LinkToFile:=False, _
SaveWithDocument:=True, Range:=oRg)
' resize picture to fit cell
With oPic
PicWd = .Width
PicHt = .Height
' find the scale factor that makes the
' picture fit without stretching the cell
ScaleFactor = Min(ColWd / PicWd, RowHt / PicHt)
' don't enlarge the picture
If ScaleFactor > 1# Then ScaleFactor = 1#
' change the size in both directions
' by the same factor
.Height = .Height * ScaleFactor
.Width = .Width * ScaleFactor
End With
bye:
' clean up
ActiveDocument.Protect Type:=ProtType, NoReset:=True
Set oPic = Nothing
Set oRg = Nothing
Set oCell = Nothing
Set oTbl = Nothing
End Sub
Private Function Min(a As Single, b As Single) As Single
If a < b Then
Min = a
Else
Min = b
End If
End Function
--
Regards,
Jay Freedman
Microsoft Word MVP
Laura said:
Hi Jay
- There is more than one table. However, its the 1st table
I want it in.
- And to make things even easier, its the first cell of
the first table.
- There is nothing in the cell. However, it would be nice
to have something for ppl to click on. Or something that
tells them how to insert a picture. The text can be
overwriten with the picture when completed.
- There is no specific file folder or file extension.
Ideally if the user could select from like a browser box.
Similiar to who you save or open files.
- The picture to should fit to the size of the cell
regarless of file size. The cell is squarish, if the
picture is a rectangle the longest side should fit to the
cell.
I really appreciate your help. I'm also going to look at
that link. However, my understanding of macro is very
basic and I'm pretty sure I won't beable to sort this out
on my own.
Thanks again, Laura
PS. Its Office 2002