PDA

View Full Version : Preview Building Block Content in inkEdit Control



Jfp87
09-20-2017, 09:20 AM
Guys,

I am using an inkEdit control to preview Building Block content using the following method:


Sub PreviewBBContent(CategoryName As String, BuildingBlockName As String)
Dim oBB As Word.BuildingBlock
Dim oPara As Word.Paragraph
Dim oRng As Word.Range
'Get the Building Block.
Set oBB = p_oBlockType.Categories(CategoryName).BuildingBlocks(BuildingBlockName)
'Create temp paragraph in template.
ThisDocument.Paragraphs.Add
Set oRng = ThisDocument.Paragraphs.Last.Range
'Insert the Building Block content into the scratch range.
oBB.Insert oRng
'Cut the content from the scratch range.
oRng.Cut
'Paste the content into inkPreview.
With Me.inkPreview
.Locked = False
.Text = vbNullString
SendMessage .hwnd, WM_PASTE, 0&, 0&
.Locked = True
End With
ThisDocument.Undo 3
lbl_Exit:
Exit Sub
End Sub

I think it's quite a crude method. Does anyone have a better way of getting the BB content into the inkEdit control without having to insert new paragraphs etc.?

Joe

gmaxey
09-20-2017, 03:39 PM
Your code doesn't compile. Where is WM_PASTE defined.

gmaxey
09-20-2017, 06:14 PM
Joe,

Crude probably still applies but here is an alternative:


Option Explicit
Private Const WM_CUT = &H300
Private Const WM_COPY = &H301
Private Const WM_PASTE = &H302
Private Const WM_CLEAR = &H303
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Private Sub UserForm_Initialize()
PreviewBBContent "General", "Car"
End Sub
Sub PreviewBBContent(CategoryName As String, BuildingBlockName As String)
Dim oBBT As BuildingBlockType
Dim oBB As Word.BuildingBlock
Dim oTmpDoc As Document
'Get the Building Block.
Set oBBT = ThisDocument.AttachedTemplate.BuildingBlockTypes(wdTypeAutoText)
Set oBB = oBBT.Categories(CategoryName).BuildingBlocks(BuildingBlockName)
Set oTmpDoc = Documents.Add(, , , False)
oBB.Insert oTmpDoc.Range
oTmpDoc.Range.Cut
oTmpDoc.Close wdDoNotSaveChanges
With InkEdit1
.Locked = False
.Text = vbNullString
SendMessage .hWnd, WM_PASTE, 0&, 0&
.Locked = True
End With
lbl_Exit:
Exit Sub
End Sub

Jfp87
09-21-2017, 12:30 AM
Looks like I will just have to stick with the cut & paste option.

Thanks for that Greg.