HI Guys, I apologise if this has already been asked but I have been trying to get a signature box for a excel document I'm building
I have come across two issues one I think is just down to the code I have in there. Ill probably figure that one out when I get the next issue sorted
the main issue I have is when I bring up the userform that lets you sign your name or whatever in there using an ink picture I want the 4x3" graphics tablet I have for signing to be the whole userform box.
is there a way to set it so that the sign pad takes the userform as the full size of the pad rather than a small 1 inch box dependant on where the box appears
any help would be greatly appreciated
the code I have in there at the moment is this
and a separate module with
I have come across two issues one I think is just down to the code I have in there. Ill probably figure that one out when I get the next issue sorted
the main issue I have is when I bring up the userform that lets you sign your name or whatever in there using an ink picture I want the 4x3" graphics tablet I have for signing to be the whole userform box.
is there a way to set it so that the sign pad takes the userform as the full size of the pad rather than a small 1 inch box dependant on where the box appears
any help would be greatly appreciated
the code I have in there at the moment is this
Code:
Option Explicit
Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
Private Type POINT
x As Long
y As Long
End Type
Private Declare Sub ClipCursor Lib "user32" (lpRect As Any)
Private Declare Sub GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT)
Private Declare Sub ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINT)
Private Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long)
'Added this declaration to get userform window handle
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub CommandButton3_Click()
'Limits the Cursor movement to within the form.
Dim client As RECT
Dim upperleft As POINT
Dim hWnd As Long
'Get Userform handle
hWnd = FindWindow(vbNullString, Me.Caption)
'Get information about our window
GetClientRect hWnd, client
upperleft.x = client.left
upperleft.y = client.top
'Make the bottom and right the same as the top/left
' client.bottom = client.top
' client.right = client.left
'Convert window coordinates to screen coordinates
ClientToScreen hWnd, upperleft
'offset our rectangle
OffsetRect client, upperleft.x, upperleft.y
'limit the cursor movement
ClipCursor client
End Sub
Private Sub SignPicture_Stroke(ByVal Cursor As MSINKAUTLib.IInkCursor, ByVal Stroke As MSINKAUTLib.IInkStrokeDisp, Cancel As Boolean)
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'Releases the cursor limits
ClipCursor ByVal 0&
End Sub
Private Sub CommandButton1_Click()
ClipCursor ByVal 0&
'dim object type and byte array to save from binary
Dim objInk As MSINKAUTLib.InkPicture
Dim bytArr() As Byte
Dim File1 As String
Dim filepath As String
'get temp file path as $user\Temp\[file name]
filepath = "location of file"
' set objInk as image/strokes of InkPicture control form object
Set objInk = Me.SignPicture
'if object is not empty
If objInk.Ink.Strokes.Count > 0 Then
'get bytes from object save
bytArr = objInk.Ink.Save(2)
'create file for output
Open filepath For Binary As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL]
'output/write bytArr into [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] /created (empty)file
Put [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , , bytArr
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL]
End If
'set public File as file path to be used later on main sub
signature.File = filepath
Call collect_signature
Unload Me
End Sub
Private Sub CommandButton2_Click()
'delete strokes/lines of signature
Me.SignPicture.Ink.DeleteStrokes
'refresh form
Me.Repaint
End Sub
Code:
Sub collect_signature()
ActiveWorkbook.Sheets("Sheet 3").Activate
Worksheets("Order Form").Range("B26").Select
'insert image/signature from temp file into application active sheet
Set SignatureImage = Application.Worksheets("sheet 3").Shapes.AddPicture(File, False, True, 1, 1, 1, 1)
'scale image/signature
SignatureImage.ScaleHeight 1, True
SignatureImage.ScaleWidth 1, True
'image/signature position
SignatureImage.top = Range("B26").top
SignatureImage.left = Range("B26").left + 40
SignatureImage.Height = 70
SignatureImage.Width = 240
'delete temp file
Kill File
If Worksheets("Start Page").Range("N1").Value = "New" Then
ActiveWorkbook.Sheets("Sheet 1").Activate
ElseIf Worksheets("Start Page").Range("N1").Value = "Used" Then
ActiveWorkbook.Sheets("Sheet 2").Activate
End If
End Sub