G
Greg Maxey
Working with shapes is not one of my favorite pastimes. Regardless, I was
recently asked to work out a method of duplicating floating shapes at
several different locations in a document. The first section of the
document serves as a data sheet and uses formfields to collect common data
(e.g., borrower name, borrower address, lender name, property address, etc)
that is used throughout the remainer of the document. I used REF fields
where appropriate to insert the common data. The form owner wanted to
insert images (jpg format graphic files) of the signature of the key parties
in the document (e.g., borrower, co-borrower, trustee, etc.) into the data
sheet and then have these signature images replicated at various points
throughout the document. Using images inserted as InLineShapes was simple
enough. It was just a matter of bookmarking the image and using REF. For
reasons still not understood, the form owner insisted on floating images
inserted behind text.
I could not find a way (if it exists) to bookmark and reference a floating
image. The solution I came up with is described below.
1. In the data sheet I inserted a two column mulit-row table. The first
column contains macrobutton fields that calls a procedure that allows the
user to browse for and insert the floating image in the second column.
E.g.,
{ Macrobutton GetSigBPic "Borrower Signature" } which displays as "Borrower
Signature." Each of these macrobuttons runs a short procedure with calls to
other procedures as shown in the example below:
SelectedFile = ImagePath
If SelectedFile <> "" Then InsertSIG SelectedFile, 1, "SigB"
End Sub
2. The form owner wanted the signature size to be limited to 1 inch high
by 3 inches wide. I set the row height of the table to exactly 1" and set
the column autofit to "fixed column width.
3. I added bookmarks throughout the document where the various signature
images collected in the data sheet needed to be duplicated. I used
sequentially numbered bookmarks for each party signature. E.g.,
SigBCopy1, SigBCopy2, SigBCopy3 etc. where SigB represents the borrower
signature.
4. The form is protected so I used and AutoOpen macro to set the
ButtonFieldClick option to 1. This allows the macrobuttons to function in
the form.
5. The main procedure first evaluates the document and deletes any previous
signtature image in the data sheet placeholder and any copies at the various
bookmark anchors. Next it inserts, sized and formats the image into the
data sheet placeholder then copies and pastes the image at the bookmark
anchors.
6. The complete code is shown below.
This process is working, but I feel like Rube Goldberg had a hand in it. I
was wondering if anyone else has put together something simplier to do the
same job.
Thanks.
Option Explicit
Dim SelectedFile As String
Sub AutoOpen()
Options.ButtonFieldClicks = 1
End Sub
Sub GetSIGBPic()
SelectedFile = ImagePath
If SelectedFile <> "" Then InsertSIG SelectedFile, 1, "SigB"
End Sub
Sub GetSIGCPic()
SelectedFile = ImagePath
If SelectedFile <> "" Then InsertSIG SelectedFile, 2, "SigC"
End Sub
Sub GetSIGTPic()
SelectedFile = ImagePath
If SelectedFile <> "" Then InsertSIG SelectedFile, 3, "SigT"
End Sub
Function ImagePath() As String
With Application.FileDialog(msoFileDialogFilePicker)
If .Show Then
ImagePath = .SelectedItems(1)
Else
ImagePath = ""
End If
End With
If ImagePath = "" Then MsgBox "You did not select a file"
End Function
Sub InsertSIG(ByRef pName As String, i As Long, pStr As String)
Dim bProtected As Boolean
Dim oShape As shape
Dim oRng As Word.Range
Dim j As Long
Dim oBM As Bookmark
bProtected = False
'Delete previous signature image master and and copies
Set oRng = ActiveDocument.Tables(1).Cell(i, 2).Range
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect
End If
Application.ScreenUpdating = False
For Each oShape In oRng.ShapeRange
oShape.Delete
Next
For j = ActiveDocument.Shapes.Count To 1 Step -1
Set oShape = ActiveDocument.Shapes(j)
If InStr(oShape.Name, pStr) Then
oShape.Delete
End If
Next
'Insert, size and copy master signature image
Set oShape = ActiveDocument.Shapes.AddPicture(FileName:=pName,
LinkToFile:=False, SaveWithDocument:=True, Anchor:=oRng)
With oShape
If .Height > InchesToPoints(1) Then .Height = InchesToPoints(1)
If .Width > InchesToPoints(3) Then .Width = InchesToPoints(3)
If .Type = msoPicture Then oShape.WrapFormat.Type = wdWrapNone
.ZOrder msoSendBehindText
.Name = pStr
.Select
End With
Selection.Copy
'Create duplicates anchored at each designated BM
For Each oBM In ActiveDocument.Bookmarks
If InStr(oBM.Name, pStr & "Copy") Then
Set oRng = oBM.Range
oRng.Paste
Set oShape = oRng.ShapeRange(1)
With oShape
.Name = "Copy" & pStr
.RelativeHorizontalPosition = wdRelativeHorizontalPositionCharacter
.Top = InchesToPoints(0)
.Left = InchesToPoints(0)
End With
End If
Next oBM
Set oShape = Nothing
Application.ScreenUpdating = True
If bProtected Then
ActiveDocument.Protect wdAllowOnlyFormFields, True
End If
End Sub
Sub Document_Close()
'Clear clipboard to avoid on exit message of clipboard contents
Dim MyData As DataObject
Set MyData = New DataObject
MyData.SetText ""
MyData.PutInClipboard
End Sub
recently asked to work out a method of duplicating floating shapes at
several different locations in a document. The first section of the
document serves as a data sheet and uses formfields to collect common data
(e.g., borrower name, borrower address, lender name, property address, etc)
that is used throughout the remainer of the document. I used REF fields
where appropriate to insert the common data. The form owner wanted to
insert images (jpg format graphic files) of the signature of the key parties
in the document (e.g., borrower, co-borrower, trustee, etc.) into the data
sheet and then have these signature images replicated at various points
throughout the document. Using images inserted as InLineShapes was simple
enough. It was just a matter of bookmarking the image and using REF. For
reasons still not understood, the form owner insisted on floating images
inserted behind text.
I could not find a way (if it exists) to bookmark and reference a floating
image. The solution I came up with is described below.
1. In the data sheet I inserted a two column mulit-row table. The first
column contains macrobutton fields that calls a procedure that allows the
user to browse for and insert the floating image in the second column.
E.g.,
{ Macrobutton GetSigBPic "Borrower Signature" } which displays as "Borrower
Signature." Each of these macrobuttons runs a short procedure with calls to
other procedures as shown in the example below:
SelectedFile = ImagePath
If SelectedFile <> "" Then InsertSIG SelectedFile, 1, "SigB"
End Sub
2. The form owner wanted the signature size to be limited to 1 inch high
by 3 inches wide. I set the row height of the table to exactly 1" and set
the column autofit to "fixed column width.
3. I added bookmarks throughout the document where the various signature
images collected in the data sheet needed to be duplicated. I used
sequentially numbered bookmarks for each party signature. E.g.,
SigBCopy1, SigBCopy2, SigBCopy3 etc. where SigB represents the borrower
signature.
4. The form is protected so I used and AutoOpen macro to set the
ButtonFieldClick option to 1. This allows the macrobuttons to function in
the form.
5. The main procedure first evaluates the document and deletes any previous
signtature image in the data sheet placeholder and any copies at the various
bookmark anchors. Next it inserts, sized and formats the image into the
data sheet placeholder then copies and pastes the image at the bookmark
anchors.
6. The complete code is shown below.
This process is working, but I feel like Rube Goldberg had a hand in it. I
was wondering if anyone else has put together something simplier to do the
same job.
Thanks.
Option Explicit
Dim SelectedFile As String
Sub AutoOpen()
Options.ButtonFieldClicks = 1
End Sub
Sub GetSIGBPic()
SelectedFile = ImagePath
If SelectedFile <> "" Then InsertSIG SelectedFile, 1, "SigB"
End Sub
Sub GetSIGCPic()
SelectedFile = ImagePath
If SelectedFile <> "" Then InsertSIG SelectedFile, 2, "SigC"
End Sub
Sub GetSIGTPic()
SelectedFile = ImagePath
If SelectedFile <> "" Then InsertSIG SelectedFile, 3, "SigT"
End Sub
Function ImagePath() As String
With Application.FileDialog(msoFileDialogFilePicker)
If .Show Then
ImagePath = .SelectedItems(1)
Else
ImagePath = ""
End If
End With
If ImagePath = "" Then MsgBox "You did not select a file"
End Function
Sub InsertSIG(ByRef pName As String, i As Long, pStr As String)
Dim bProtected As Boolean
Dim oShape As shape
Dim oRng As Word.Range
Dim j As Long
Dim oBM As Bookmark
bProtected = False
'Delete previous signature image master and and copies
Set oRng = ActiveDocument.Tables(1).Cell(i, 2).Range
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect
End If
Application.ScreenUpdating = False
For Each oShape In oRng.ShapeRange
oShape.Delete
Next
For j = ActiveDocument.Shapes.Count To 1 Step -1
Set oShape = ActiveDocument.Shapes(j)
If InStr(oShape.Name, pStr) Then
oShape.Delete
End If
Next
'Insert, size and copy master signature image
Set oShape = ActiveDocument.Shapes.AddPicture(FileName:=pName,
LinkToFile:=False, SaveWithDocument:=True, Anchor:=oRng)
With oShape
If .Height > InchesToPoints(1) Then .Height = InchesToPoints(1)
If .Width > InchesToPoints(3) Then .Width = InchesToPoints(3)
If .Type = msoPicture Then oShape.WrapFormat.Type = wdWrapNone
.ZOrder msoSendBehindText
.Name = pStr
.Select
End With
Selection.Copy
'Create duplicates anchored at each designated BM
For Each oBM In ActiveDocument.Bookmarks
If InStr(oBM.Name, pStr & "Copy") Then
Set oRng = oBM.Range
oRng.Paste
Set oShape = oRng.ShapeRange(1)
With oShape
.Name = "Copy" & pStr
.RelativeHorizontalPosition = wdRelativeHorizontalPositionCharacter
.Top = InchesToPoints(0)
.Left = InchesToPoints(0)
End With
End If
Next oBM
Set oShape = Nothing
Application.ScreenUpdating = True
If bProtected Then
ActiveDocument.Protect wdAllowOnlyFormFields, True
End If
End Sub
Sub Document_Close()
'Clear clipboard to avoid on exit message of clipboard contents
Dim MyData As DataObject
Set MyData = New DataObject
MyData.SetText ""
MyData.PutInClipboard
End Sub