W
Wylie C
I have the following code developed that works great in Word 2000 but does
not run in Word 97. Basically there are macro form fields inserted with
consecutive numbers. When the user clicks on the form field, it unlocks the
form, brings up the explorer window and allow the user to select a graphic,
protects the document again and goes to the next record. What and where in
the code needs changed? (Source code would be greatly appreciated).
Thank you...very much
Public Sub FormInsertPicture()
Static intCount As Integer
Dim FName As String, LocName As String
Dim PicRg As Range
Dim Photo As InlineShape
Dim Ratio As Single
Dim strRecordNum As String
Dim strNextRecord As String
Dim strPicNum As String
Dim strCurrPicNum As String
intCount = intCount + 1
strRecordNum = "Record"
strPicNum = "Pic"
strCurrPicNum = strPicNum & intCount
' if bookmark for locating picture is renamed,
' change the item in quotes below
LocName = strCurrPicNum
With ActiveDocument
If Not .Bookmarks.Exists(LocName) Then GoTo BadRange
If .ProtectionType <> wdNoProtection Then
.Unprotect
End If
' standard Insert > Picture > From File dialog
' [Note: If you try to call the dialog before you
' unprotect the document, it doesn't work.]
With Dialogs(wdDialogInsertPicture)
If .Display <> -1 Then GoTo Canceled
' get chosen file's full path and file name
' (see http://word.mvps.org/FAQs/MacrosVBA/WordBasicCommands.htm)
FName = WordBasic.FileNameInfo$(.Name, 1)
End With
' create range for picture location
Set PicRg = .Bookmarks(LocName).Range
' if a picture is already there, delete it
Do While PicRg.InlineShapes.Count > 0
PicRg.InlineShapes(1).Delete
Loop
' insert the picture
Set Photo = .InlineShapes.AddPicture(FileName:=FName, _
LinkToFile:=False, SaveWithDocument:=True, _
Range:=PicRg)
With Photo
' size the picture to fit the column
Ratio = InchesToPoints(2.75) / .Width
.Height = 72
.Width = 68
End With
' re-add the bookmark so it can be reused
' I commented the following line out; don't need range name again
'.Bookmarks.Add Name:=LocName, Range:=Photo.Range
Canceled:
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End With
' deletes the now used bookmark
ActiveDocument.Bookmarks(strCurrPicNum).Delete
intCount = intCount + 1
strNextRecord = strRecordNum & intCount
If intCount <= 8 Then
Selection.GoTo what:=wdGoToBookmark, Name:=strNextRecord
intCount = intCount - 1
Else
Exit Sub
End If
BadRange:
End Sub
not run in Word 97. Basically there are macro form fields inserted with
consecutive numbers. When the user clicks on the form field, it unlocks the
form, brings up the explorer window and allow the user to select a graphic,
protects the document again and goes to the next record. What and where in
the code needs changed? (Source code would be greatly appreciated).
Thank you...very much
Public Sub FormInsertPicture()
Static intCount As Integer
Dim FName As String, LocName As String
Dim PicRg As Range
Dim Photo As InlineShape
Dim Ratio As Single
Dim strRecordNum As String
Dim strNextRecord As String
Dim strPicNum As String
Dim strCurrPicNum As String
intCount = intCount + 1
strRecordNum = "Record"
strPicNum = "Pic"
strCurrPicNum = strPicNum & intCount
' if bookmark for locating picture is renamed,
' change the item in quotes below
LocName = strCurrPicNum
With ActiveDocument
If Not .Bookmarks.Exists(LocName) Then GoTo BadRange
If .ProtectionType <> wdNoProtection Then
.Unprotect
End If
' standard Insert > Picture > From File dialog
' [Note: If you try to call the dialog before you
' unprotect the document, it doesn't work.]
With Dialogs(wdDialogInsertPicture)
If .Display <> -1 Then GoTo Canceled
' get chosen file's full path and file name
' (see http://word.mvps.org/FAQs/MacrosVBA/WordBasicCommands.htm)
FName = WordBasic.FileNameInfo$(.Name, 1)
End With
' create range for picture location
Set PicRg = .Bookmarks(LocName).Range
' if a picture is already there, delete it
Do While PicRg.InlineShapes.Count > 0
PicRg.InlineShapes(1).Delete
Loop
' insert the picture
Set Photo = .InlineShapes.AddPicture(FileName:=FName, _
LinkToFile:=False, SaveWithDocument:=True, _
Range:=PicRg)
With Photo
' size the picture to fit the column
Ratio = InchesToPoints(2.75) / .Width
.Height = 72
.Width = 68
End With
' re-add the bookmark so it can be reused
' I commented the following line out; don't need range name again
'.Bookmarks.Add Name:=LocName, Range:=Photo.Range
Canceled:
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End With
' deletes the now used bookmark
ActiveDocument.Bookmarks(strCurrPicNum).Delete
intCount = intCount + 1
strNextRecord = strRecordNum & intCount
If intCount <= 8 Then
Selection.GoTo what:=wdGoToBookmark, Name:=strNextRecord
intCount = intCount - 1
Else
Exit Sub
End If
BadRange:
End Sub