Hi.
The following code will take only one item from the clipboard and paste it into each bookmark. I am trying to get 3 different items that are w/in the clipboard and replace the bookmarks with the clipboard items. For example I need the address from the clipboard to replace the address field. I need the auto_num from the clip board to replace the auto_num bookmark and finally I need the price from the clipboard to replace the amt_due bookmark. The FillBookmarks function replaces the bookmarks w/ in the document because for some reason and with all the research I have done once you run this macro, the bookmarks are removed.
So to reiterate my problem again if not clear.
1.) I have only 3 item stored on the clipboard and each item will replace each bookmark.
2.) The following code works fine, but only uses the last item copied or selected from the clipboard and replaces all three bookmark references.
Hope that is clear enough and any help would be great.
Thank you.
Rich
Sub cpyclpbrd()
Selection.GoTo What:=wdGoToBookmark, Name:="address"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.Paste
Selection.GoTo What:=wdGoToBookmark, Name:="auto_num"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.Paste
Selection.GoTo What:=wdGoToBookmark, Name:="amt_due"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.Paste
FillBookmark wdDoc, sAddress, "address"
FillBookmark wdDoc, lLoanNum, "auto_num", "0"
FillBookmark wdDoc, lPastDue, "amt_due", "0"
ActiveDocument.PrintOut
End Sub
Sub FillBookmark(ByRef wdDoc As Object, _
ByVal vValue As Variant, _
ByVal sBmName As String, _
Optional sFormat As String)
Dim wdRng As Object
Set wdRng = wdDoc.Bookmarks(sBmName).Range
If Len(sFormat) = 0 Then
wdRng.Text = vValue
Else
wdRng.Text = Format(vValue, sFormat)
End If
wdRng.Bookmarks.Add sBmName, wdRng
End Sub
The following code will take only one item from the clipboard and paste it into each bookmark. I am trying to get 3 different items that are w/in the clipboard and replace the bookmarks with the clipboard items. For example I need the address from the clipboard to replace the address field. I need the auto_num from the clip board to replace the auto_num bookmark and finally I need the price from the clipboard to replace the amt_due bookmark. The FillBookmarks function replaces the bookmarks w/ in the document because for some reason and with all the research I have done once you run this macro, the bookmarks are removed.
So to reiterate my problem again if not clear.
1.) I have only 3 item stored on the clipboard and each item will replace each bookmark.
2.) The following code works fine, but only uses the last item copied or selected from the clipboard and replaces all three bookmark references.
Hope that is clear enough and any help would be great.
Thank you.
Rich
Sub cpyclpbrd()
Selection.GoTo What:=wdGoToBookmark, Name:="address"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.Paste
Selection.GoTo What:=wdGoToBookmark, Name:="auto_num"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.Paste
Selection.GoTo What:=wdGoToBookmark, Name:="amt_due"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.Paste
FillBookmark wdDoc, sAddress, "address"
FillBookmark wdDoc, lLoanNum, "auto_num", "0"
FillBookmark wdDoc, lPastDue, "amt_due", "0"
ActiveDocument.PrintOut
End Sub
Sub FillBookmark(ByRef wdDoc As Object, _
ByVal vValue As Variant, _
ByVal sBmName As String, _
Optional sFormat As String)
Dim wdRng As Object
Set wdRng = wdDoc.Bookmarks(sBmName).Range
If Len(sFormat) = 0 Then
wdRng.Text = vValue
Else
wdRng.Text = Format(vValue, sFormat)
End If
wdRng.Bookmarks.Add sBmName, wdRng
End Sub