VBAコードは非常にうまく機能します。私は、複数のサイズの図形を変更することはできますが、丸められた数値に対してのみ動作しています。私が形状のサイズを2.5または5.5に変更するようにしたら、動作しませんが、変数のデータ型は倍です。何か案は? 形状のサイズを変更するためのデータ型
あなたはinteger
として結果をキャスト
objHeigh = CInt(InputBox$("Assign a new size of Height", "Heigh"))
でCInt
を使用するためです
Function ConvertPointToCm(ByVal pnt As Double) As Double
ConvertPointToCm = pnt * 0.03527778
End Function
Function ConvertCmToPoint(ByVal cm As Double) As Double
ConvertCmToPoint = cm * 28.34646
End Function
Sub test()
Dim objHeigh As Double
Dim objWidth As Double
Dim oSh As Shape
On Error GoTo CheckErrors
With ActiveWindow.Selection.ShapeRange
If .Count = 0 Then
MsgBox "You need to select a shape first"
Exit Sub
End If
End With
objHeigh = CInt(InputBox$("Assign a new size of Height", "Heigh"))
' give the user a way out
If objHeigh = 0 Then
Exit Sub
End If
objHeigh = ConvertCmToPoint(objHeigh)
objWidth = CInt(InputBox$("Assign a new size of Width", "Width"))
' give the user a way out
If objWidth = 0 Then
Exit Sub
End If
objWidth = ConvertCmToPoint(objWidth)
For Each oSh In ActiveWindow.Selection.ShapeRange
If objName <> "" Then
oSh.Name = objName
End If
oSh.Height = CInt(objHeigh)
oSh.Width = CInt(objWidth)
Next
Exit Sub
CheckErrors: MsgBox Err.Description
End Sub
あなたが「動作しない」とはどういう意味ですか? –