PDA

View Full Version : VBA code to use Other Programs with Excel



Courtney
04-24-2012, 02:28 PM
I Have 2 downloaded Products that support excel
1) screen Caliper............iconico.com/caliper/
SDK Download..............iconico.com/caliper/SDKDemo.aspx
2) Screen Protractor...... .iconico.com/protractor/
SDK Download...............iconico.com/protractor/SDKDemo.aspx
To Load both Programs I Have written this code and it loads Perfect
Private Sub Cmdload_Click()
Call Shell("C:\Program Files\screen calipers 4.0\calipers")
Call Shell("C:\Program Files\screen protractor 4.0\Protractor")
End Sub
On the screen Protractor
I Have a VBA form that pulls info form Various sheets. In this Form I have a Label named ‘’LblPix’’ I would Like for the SDK file to read ‘’LblPix’’ Total and automatically change the measurement to that Value.
The Code in the SDK is
Private WithEvents CaliperApp As Calipers.IconicoCalipers
Private CaliperUnits As Calipers.IIconicoCalipersUnits
Private CaliperSkins As Calipers.IIconicoCalipersSkins

Private Sub cmdConnect_Click()
CheckConnected
End Sub
Private Sub cmdDisconnect_Click()
Set CaliperSkins = Nothing
Set CaliperUnits = Nothing
Set CaliperApp = Nothing
Cells(6, 7).Value = "Not Connected"
End Sub

'Checks connection to the Caliper Application, making a connection if needed
Private Function CheckConnected() As Boolean
If (CaliperApp Is Nothing) Then
'Calipers not initialized
On Error GoTo AutomationError
Set CaliperApp = New Calipers.IconicoCalipers
Set CaliperSkins = CaliperApp.Skins
Set CaliperUnits = CaliperApp.Units
Cells(6, 7).Value = "Connected"
End If
'Calipers might have previously been closed by the user, so we check if we can access a property
On Error GoTo CaliperError
Dim strTemp As String
strTemp = CaliperApp.Measurement
CheckConnected = True
Exit Function
AutomationError:
MsgBox ("Could not connect to Screen Calipers - Please check that you have the Calipers installed")
CheckConnected = False
Exit Function
CaliperError:
On Error GoTo AutomationError
Set CaliperSkins = Nothing
Set CaliperUnits = Nothing
Set CaliperApp = Nothing
'reset caliper
Set CaliperApp = New Calipers.IconicoCalipers
Set CaliperSkins = CaliperApp.Skins
Set CaliperUnits = CaliperApp.Units
Cells(6, 7).Value = "Connected"
CheckConnected = True
Exit Function

End Function

Private Sub CaliperApp_OnUpdate()
On Error Resume Next
Cells(10, 2).Value = CaliperApp.Measurement
Cells(12, 2).Value = CaliperApp.DisplayMeasurement
End Sub

Private Sub cmdSetMeasurement_Click()
If CheckConnected() Then
CaliperApp.Measurement = Cells(10, 3).Value
CaliperApp.Repaint
End If
End Sub

Private Sub cmdSetDisplayMeasurement_Click()
If CheckConnected() Then
CaliperApp.DisplayMeasurement = Cells(12, 3).Value
CaliperApp.Repaint
End If
End Sub


This works Independently But I can Not Get it to load in my Form.
Screen Protractor

Here I Want the Value “Degrees” To Be put onto the same form. I have Downloaded The SDK file but cant seem to get that to work at all.
In The form I have a Text Box named TxtDir I want the “ Degrees” Value put in the Txt Box Dir from the Protractor. This I don’t have the code for or have any Idea how to even Start.
Please Help me with Both Codes.
Thanking you kindly
Courtney