Below is my code for creating a shape at the cursor position.
Currently, I use Ctrl+v to run this sub routine. I would like to modify the code so that if I press Ctrl+v to call the function and then hold down the shift key while I click, the shape will be connected to the previously placed shape. Is there a line of code or anything that I can place in the sub routine that will check whether the shift key is pressed AFTER the routine is called? (The problem is, if shift is pressed while Ctrl+v is pressed to call the sub routine, it sees it as Shift+Ctrl+V, which will not run the function)
So this is how it should go.
User presses Ctrl+v to call the sub routine. User then clicks on the screen to paste the shape at the cursor position.
-OR-
User presses Ctrl+v to call the sub routine. User then presses the shift key and clicks on the screen which pastes the shape at the cursor position, then adds a connector shape to the previous shape.
Currently, I use Ctrl+v to run this sub routine. I would like to modify the code so that if I press Ctrl+v to call the function and then hold down the shift key while I click, the shape will be connected to the previously placed shape. Is there a line of code or anything that I can place in the sub routine that will check whether the shift key is pressed AFTER the routine is called? (The problem is, if shift is pressed while Ctrl+v is pressed to call the sub routine, it sees it as Shift+Ctrl+V, which will not run the function)
So this is how it should go.
User presses Ctrl+v to call the sub routine. User then clicks on the screen to paste the shape at the cursor position.
-OR-
User presses Ctrl+v to call the sub routine. User then presses the shift key and clicks on the screen which pastes the shape at the cursor position, then adds a connector shape to the previous shape.
Code:
Sub Connect_Shape()
Dim x As Single, y As Single, ShapeWidth As Single, ShapeHeight As Single
Dim EndCon As Integer
Application.ScreenUpdating = False
If ActiveSheet.Name <> "PROCESS FLOW" Then Exit Sub
ShapeWidth = 20
ShapeHeight = 20
Call GetPoints(x, y) 'Determine x,y position of cursor
x = x - (ShapeWidth / 2)
y = y - (ShapeHeight / 2)
SetCounter
'ShiftKeyState = GetKeyState(vbKeyShift) 'Where can I put this code?
Select Case Worksheets("PROCESS FLOW").Range("BL3").Value
Case "PARTS / MATERIAL"
ActiveSheet.Shapes.AddShape(msoShapeIsoscelesTriangle, x, y, ShapeWidth, ShapeHeight).Name = "Pr0" & counter
Exit Sub
Case "PROCESS"
ActiveSheet.Shapes.AddShape(msoShapeOval, x, y, ShapeWidth, ShapeHeight).Name = "Pr0" & counter
Case "INSPECTION"
ActiveSheet.Shapes.AddShape(msoShapeDiamond, x, y, ShapeWidth, ShapeHeight).Name = "Pr0" & counter
Case "PROCESS / INSPECTION"
ActiveSheet.Shapes.AddShape(msoShapeOval, x, y, ShapeWidth, ShapeHeight).Name = "a" & counter
ActiveSheet.Shapes("a" & counter).Select
Selection.Characters.Text = counter
With Selection.Font
.Size = 7
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
ActiveSheet.Shapes.AddShape(msoShapeDiamond, x + 2, y + 2, ShapeWidth - 4, ShapeHeight - 4).Name = "b" & counter
ActiveSheet.Shapes("b" & counter).Select
Selection.ShapeRange.Fill.Visible = msoFalse
ActiveSheet.Shapes.Range(Array("a" & counter, "b" & counter)).Select
Selection.ShapeRange.Group.Name = "Pr0" & counter
Case "ASSEMBLY"
ActiveSheet.Shapes.AddShape(msoShapeIsoscelesTriangle, x, y, ShapeWidth, ShapeHeight).Name = "Pr0" & counter
ActiveSheet.Shapes.AddShape(msoShapeIsoscelesTriangle, x + 5.5, y + 8, ShapeWidth - 11, ShapeHeight - 11).Name = "Pr0" & counter
Exit Sub
End Select
If ShiftKeyState And &H8000 Then
ActiveSheet.Shapes.AddConnector(msoConnectorStraight, 461.25, 204#, 1.5, 22.5).Name = "C0" & counter
ActiveSheet.Shapes("C0" & counter).Select
Selection.ShapeRange.ConnectorFormat.BeginConnect ActiveSheet.Shapes("Pr0" & counter), 1
Selection.ShapeRange.ConnectorFormat.EndConnect ActiveSheet.Shapes("Pr0" & counter - 1), 1
Selection.ShapeRange.ZOrder msoSendToBack
x = ActiveSheet.Shapes("Pr0" & counter - 1).Left
ActiveSheet.Shapes("Pr0" & counter).Left = x
y = ActiveSheet.Shapes("Pr0" & counter - 1).Top + 30
ActiveSheet.Shapes("Pr0" & counter).Top = y
End If
Default:
ActiveSheet.Shapes("Pr0" & counter).Select
Selection.OnAction = "Add_Detail"
If ActiveSheet.Shapes("Pr0" & counter).AutoShapeType <> -2 Then
Selection.Characters.Text = counter
Selection.Font.Size = 7
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End If
ActiveSheet.Shapes.AddLabel(msoTextOrientationHorizontal, x + 35, y + 2.5, 0, 0).Name = "T0" & counter
ActiveSheet.Shapes("T0" & counter).TextFrame.Characters.Text = "INSERT TEXT HERE"
Application.ScreenUpdating = True
End Sub