0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Access VBA Cmをポイントに変換する ポイントをCm、mmに変換するユーザー定義関数

Posted at

AccessにはCentimetersToPointsがない

Excelにはあるのに、Accessにはありません

Excelとデータ型に差が

このためPublisherがある人はPublisherを、ない人はWordを使いますが、
DoubleではなくSingleのデータ型になります。まあこれはExcelを使えばいいのですが、こんどはポイントをCmにする関数がありません。

PublisherとWordの差

速度的には不明ですが、PublisherはQuitをつけなくても終了します。
しかしWordは終了しません。タスクマネージャで見るといっぱい起動します。
PublisherはOulookと同じで1個しか起動しません。このため増えないのです。
なのでOffice365 Soloを持っているとか会社でOfficeを使っている人はPublisherを使う方が良いようです。しかし汎用性ではWordに負けますが、WordはQuitを入れないと大変なことになるので注意してください。

端数処理

AccessにはExcelのRound関数はありません。このためFixを使っています。


Public Function CmToPoint(CentiMenterUnitNum As Single) As Single
On Error Resume Next
Dim CentiMeterDouble As Double
CentiMeterDouble = CDbl(CentiMenterUnitNum)
If Err.Number = 0 Then CmToPoint = CentimetersToPoints(CentiMeterDouble) Else CmToPoint = 0
End Function
Public Function PtToCM(PointUnitDouble As Double) As Single
On Error Resume Next
Dim PointSingle As Single
'Dim wApp: Set wApp = CreateObject("Word.Application")
Dim pApp: Set pApp = CreateObject("Publisher.Application")
PointSingle = CSng(PointUnitDouble)
If Err.Number = 0 Then PtToCM = Fix((wApp.PointsToCentimeters(PointSingle) * 100000) + 0.5) / 100000 Else PtToCM = 0: Debug.Print Err.Number, Err.Description: Err.Clear: Exit Function
'wApp.Quit: Set pApp = Nothing
Set wApp = Nothing
End Function


Public Function PtToMM(PointUnitVariant As Variant) As Single
On Error Resume Next
Dim PointSingle As Single
'Dim wApp: Set wApp = CreateObject("Word.Application")
Dim pApp: Set pApp = CreateObject("Publisher.Application")
PointSingle = CSng(PointUnitVariant)
If Err.Number = 0 Then PtToMM = Fix((pApp.PointsToMillimeters(PointSingle) * 100000) + 0.5) / 100000 Else PtToMM = 0: Debug.Print Err.Number, Err.Description: Err.Clear: Exit Function
Set pApp = Nothing
'wApp.Quit: Set wApp = Nothing
End Function
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?