Load UserForm InkPicture with Ink saved in Excel worksheet

zeus

New Member
Joined
Dec 31, 2003
Messages
44
Hello,
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:

Me.InkPicture1.ink.ClipboardCopy
ActiveSheet.Paste
Set newImg = Selection
With newImg
.Top = 10
.Left = 10
.Name = "Signature"
End With

Thank you if you have any thoughts to share!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hello

An example:

XbtagmU.jpg



Code:
'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
Sheets("sheet1").Shapes("ink").Copy
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
 
Upvote 0
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!
 
Upvote 0
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:
Me.InkPicture1.Ink.DeleteStrokes
Me.Repaint

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!!!
 
Upvote 0
Do you have the PasteToControl api declaration inside the UserForm Module ?
 
Upvote 0
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.
 
Upvote 0
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 .
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top