Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Load UserForm InkPicture with Ink saved in Excel worksheet
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Dec 2003
    Posts
    44
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Load UserForm InkPicture with Ink saved in Excel worksheet

    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!

  2. #2
    Board Regular Worf's Avatar
    Join Date
    Oct 2011
    Location
    Rio, Brazil
    Posts
    3,726
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Load UserForm InkPicture with Ink saved in Excel worksheet

    Hello

    An example:




    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 #1 
    Put #1 , 1, ib
    Close #1 
    Set newImg = ActiveSheet.Pictures.Insert(fn)
    With newImg
        .Name = "ink"
        .Top = [b50].Top
        .Left = [b50].Left
    End With
    End Sub
    Excel 2013 / Windows 8.1 (home)
    Excel 2013 / windows 7 (work)


  3. #3
    New Member
    Join Date
    Dec 2003
    Posts
    44
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Load UserForm InkPicture with Ink saved in Excel worksheet

    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!

  4. #4
    Board Regular Jaafar Tribak's Avatar
    Join Date
    Dec 2002
    Location
    Larache--Morocco
    Posts
    7,349
    Post Thanks / Like
    Mentioned
    39 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Load UserForm InkPicture with Ink saved in Excel worksheet

    @zeus

    Have you tried :

    PasteToControl InkPicture1.hWnd
    Office/Excel 2010 64Bits -- Win10 64Bits

    Common sense is not so common.


    http://photo-larache.blogspot.com/

  5. #5
    New Member
    Join Date
    Dec 2003
    Posts
    44
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Load UserForm InkPicture with Ink saved in Excel worksheet

    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!!!

  6. #6
    Board Regular Jaafar Tribak's Avatar
    Join Date
    Dec 2002
    Location
    Larache--Morocco
    Posts
    7,349
    Post Thanks / Like
    Mentioned
    39 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Load UserForm InkPicture with Ink saved in Excel worksheet

    Do you have the PasteToControl api declaration inside the UserForm Module ?
    Office/Excel 2010 64Bits -- Win10 64Bits

    Common sense is not so common.


    http://photo-larache.blogspot.com/

  7. #7
    New Member
    Join Date
    Dec 2003
    Posts
    44
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Load UserForm InkPicture with Ink saved in Excel worksheet

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

  8. #8
    Board Regular Jaafar Tribak's Avatar
    Join Date
    Dec 2002
    Location
    Larache--Morocco
    Posts
    7,349
    Post Thanks / Like
    Mentioned
    39 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Load UserForm InkPicture with Ink saved in Excel worksheet

    Quote Originally Posted by zeus View Post
    Yes, I believe I do. I pasted it in Modules > Module1
    No. You should paste it in the UserForm Module NOT in a Standard Module.
    Office/Excel 2010 64Bits -- Win10 64Bits

    Common sense is not so common.


    http://photo-larache.blogspot.com/

  9. #9
    New Member
    Join Date
    Dec 2003
    Posts
    44
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Load UserForm InkPicture with Ink saved in Excel worksheet

    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.

  10. #10
    Board Regular Jaafar Tribak's Avatar
    Join Date
    Dec 2002
    Location
    Larache--Morocco
    Posts
    7,349
    Post Thanks / Like
    Mentioned
    39 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Load UserForm InkPicture with Ink saved in Excel worksheet

    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 .
    Office/Excel 2010 64Bits -- Win10 64Bits

    Common sense is not so common.


    http://photo-larache.blogspot.com/

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •