Load UserForm InkPicture with Ink saved in Excel worksheet


New Member
I have struck out all day trying to find an answer to my problem. I would really appreciate any assistance that you can offer.
I have a UserForm with an InkPicture that I am using for approval signatures. Long story short, I have been able to save the ink strokes to the active Excel workbook, Sheet1, and what I need to do next is figure out how to load that image/strokes from the Excel worksheet back into the InkPicture when the file is reopened. Here is the code I used when saving the InkPicture strokes to the Excel sheet:

Set newImg = Selection
With newImg
.Top = 10
.Left = 10
.Name = "Signature"
End With

Thank you if you have any thoughts to share!


Well-known Member

An example:

'UserForm module
Private Declare Function PasteToControl Lib "user32" Alias "SendMessageA" _
(ByVal hWnd&, Optional ByVal wMsg& = &H302, Optional ByVal wParam& = 0, Optional lParam As Any = 0&) As Long
Private Sub CommandButton1_Click()
InkEdit1.Text = vbCrLf
PasteToControl InkEdit1.hWnd                ' back to UserForm
End Sub

Private Sub UserForm_Click()
Dim ib() As Byte, fn$, newImg
ib = Me.InkPicture1.Ink.Save(IPF_GIF)
fn = ActiveWorkbook.Path & "\test.gif"
Open fn For Binary Access Write As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
Put [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , 1, ib
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
Set newImg = ActiveSheet.Pictures.Insert(fn)
With newImg
    .Name = "ink"
    .Top = [b50].Top
    .Left = [b50].Left
End With
End Sub


New Member
Thank you so much for your response! I see where you're going and it seems like it'll work great. I'm having trouble with the line that says "PasteToControl InkEdit1.hWnd". I'm getting an error:
Compile Error: Sub or Function not defined.

Could you please provide some guidance on what I can do to resolve the error?

Thank you kindly!


New Member
Hello, I apologize for the long delay. I've been trying a few different things today. First, I changed all InkEdit1 to InkPicture1. This caused an error (Object doesn't support this property or method) on the line "InkPicture1.Text = vbCrLf". I think it's because InkPicture1 does not have the Text Property. I think the purpose of this line is to clear the InkPicture1 box so I used this code to clear the picture and it seems to work:

After I got that resolved, I'm still getting an error (Sub or Function not defined) on the line:
PasteToControl InkPicture1.hWnd ' back to UserForm

I've never written a "Public Declare Function" so I'm not doing very well at trouble shooting it. Are you able to help me understand what's causing it to get an error?

Thank you for the time you've invested so far, I really appreciate it!!!


New Member
Yes, I believe I do. I pasted it in Modules > Module1


New Member
sorry about that, that was my lack of knowledge. I was able to progress further. I'm having trouble getting the Ink back into the InkPicture. I can see that it's saving the .gif file in the same location where my form is saved, but it doesn't load it back. Maybe my order of operations is not correct.
1) I'm putting a signature in the InkPicture1 box
2) I'm clicking a button that's triggering my code to send the ink to Excel. I can see that the ink is now in Excel
3) I click CommandButton1 and the InkPicture1 strokes are deleted, and the rest of that code runs without issues but the image is not brought back into the InkPicture. It is blank
4) I click on the UserForm (the InkPicture1 is now blank due to step 3 deleting the ink) and I get an error "Method 'Save' of object 'IInkDisp' failed. The error is on line "ib = Me.InkPicture1.Ink.Save(IPF_GIF)"

Can you please guide me as to what I'm doing incorrectly. It looks like it works great for you so I must not be doing something right.

Jaafar Tribak

Well-known Member
I am not familiar with the InkPicture control object model so I am not sure if there is a propper way of pasting the ink shape from the worksheet into the ink control.

The PasteToControl api function didn' work for me either ... Maybe you could try using the vba LoadPicture function .

Some videos you may like

This Week's Hot Topics