説明
テキストフィールド、コンボボックス、リストボックス、またはボタンに配置するテキストのフォントを示します。
形式
[ 取得 / 設定 ] String
設定又は戻り値
設定、又は取得可能なフォント
- HeiseiMin-W3-UniJIS-UCS2-H (平成明朝)
- HeiseiKakuGo-W5-UniJIS-UCS2-H (平成角ゴシック)
- Courier
- Courier-Bold
- Courier-Oblique
- Courier-BoldOblique
- Helvetica
- Helvetica-Bold
- Helvetica-Oblique
- Helvetica-BoldOblique
- Symbol
- Times-Roman
- Times-Bold
- Times-Italic
- Times-BoldItalic
- ZapfDingbats
フォーム機能で使用可能な日本語フォントは、平成明朝、平成角ゴシック のみです。"平成明朝" では無く "HeiseiMin-W3-UniJIS-UCS2-H" と指定します。
動作するバージョン
| Acrobat | 結果 | 備考 |
|---|---|---|
| 4 | △ | Acrobat 4.0 ※Windows 98SE + Excel 2000 *1 |
| 5 | △ | Acrobat 5.0.5 + Excel 2003 *1 |
| 6 | △ | Acrobat 6.0.6 Pro + Excel 2003 *1 |
| 7 | OK | Acrobat 7.1.4 Pro + Excel 2003 *2 |
| 8 | NO | Acrobat 8.3.1 Pro + Excel 2003 ※当Acrobatバージョンでは全面的に不可 |
| 9 | NO | Acrobat 9.5.2 Extended + Excel 2003 ※当Acrobatバージョンでは全面的に不可 |
| 10 | OK | Acrobat X (10.1.4) Extended + Excel 2003 |
| 11 | OK | Acrobat XI (10.0) Extended + Excel 2003 |
- OK : 正常処理します。
- NO : 動作しない。 又は実行時にエラーになります。
- *1 : 「PDF のバージョン」によっては正常処理出来ない場合があります。詳細は下の 注意 を参照ください。
- *2 : 処理前のレジストリに以下を追加する必要があります。
[HKEY_CURRENT_USER¥Software¥Adobe¥Adobe Acrobat¥7.0¥AVAlert]
[HKEY_CURRENT_USER¥Software¥Adobe¥Adobe Acrobat¥7.0¥AVAlert¥cCheckbox]
"idocNewerVersionWarning"=dword:00000001
サンプル:ExcelのVBA
AFormAutのTextFontプロパテを使ったサンプルです。頁にヘッダーを追加します。
Download:
/p759_AFormAut-Field-TextFont.zip ( 23.1 KB )
001 Option Explicit
002
003 Private msMsg As String 'メッセージ
004 ' VBA RunTime Error 対応用
005 Private miErrorNo As Long 'Err.Number の内容
006 Private msErrorMsg As String 'Err.Description の内容
007
008 '**************************************************
009 ' 処理 :ヘッダー用のテキストフィールドを追加
010 ' AFormAut :TextFont プロパティ サンプル
011 ' Create :2026/02/09
012 ' Update :2026/02/09
013 ' Vertion :1.0.1
014 '**************************************************
015 Sub AFormAut_Field_TextFont()
016 On Error GoTo Err_AFormAut_Field_TextFont:
017
018 '▼メモリ上のAcrobatプロセスを確認する
019 If iCheckAcrobat() > 0 Then
020 msMsg = "Acrobatが動いています。" _
021 & vbCrLf & "処理を中断します。" & vbCrLf _
022 & vbCrLf & "この後でAcrobatの終了を試みます。"
023 MsgBox msMsg, vbCritical, "実行の中断"
024 'Acrobat OLEの終了を試みる
025 Call EndAcrobat
026 Exit Sub
027 End If
028
029 Dim i As Long
030 Dim iPageNum As Long
031 Dim bRet As Boolean
032 Dim bEnd As Boolean
033 Dim sFilePath_new As String
034
035 '初期値
036 Const CON_FILEPATH = "D:\work\Test01.pdf"
037 bEnd = True
038
039 'Acrobatオブジェクトの定義&作成
040 Dim objAFormApp As New AFORMAUTLib.AFormApp
041 Dim objAFormFields As AFORMAUTLib.Fields
042 Dim objAFormField As AFORMAUTLib.Field
043
044 'Acrobat 4,5,6 の時
045 ' Dim objAcroApp As Acrobat.CAcroApp
046 ' Dim objAcroAVDoc As Acrobat.CAcroAVDoc
047 ' Dim objAcroPDDoc As Acrobat.CAcroPDDoc
048 ' Dim objAcroPDPage As Acrobat.CAcroPDPage
049 ' Dim objAcroPoint As Acrobat.CAcroPoint
050 ' Set objAcroApp = CreateObject("AcroExch.App")
051 ' Set objAcroAVDoc = CreateObject("AcroExch.AVDoc")
052 ' Set objAcroPDDoc = CreateObject("AcroExch.PDDoc")
053
054 'Acrobat 7,8,9,10,11 の時
055 Dim objAcroApp As New Acrobat.AcroApp
056 Dim objAcroAVDoc As New Acrobat.AcroAVDoc
057 Dim objAcroPDDoc As New Acrobat.AcroPDDoc
058 Dim objAcroPDPage As Acrobat.AcroPDPage
059 Dim objAcroPoint As Acrobat.AcroPoint
060
061 '※[429 ActiveXコンポーネントはオブジェクトを作成できません。]
062 '※回避用 / メモリにAcrobatを強制ロードさせる
063 objAcroApp.CloseAllDocs
064 objAcroApp.Hide
065
066 '処理対象のPDFファイルを開く
067 bRet = objAcroAVDoc.Open(CON_FILEPATH, "")
068 If bRet = False Then
069 MsgBox "AVDocオブジェクトはOpen出来ません", _
070 vbOKOnly vbCritical, "処理エラー"
071 bEnd = False
072 GoTo Skip_AFormAut_Field_TextFont:
073 End If
074
075 Set objAcroPDDoc = objAcroAVDoc.GetPDDoc
076 iPageNum = objAcroPDDoc.GetNumPages
077 Set objAFormFields = objAFormApp.Fields
078
079 For i = 0 To iPageNum - 1
080
081 'PDFページサイズを取得
082 Set objAcroPDPage = objAcroPDDoc.AcquirePage(i)
083 Set objAcroPoint = objAcroPDPage.GetSize
084
085 '指定ページにヘッダー用のテキストフィールドを追加
086 Set objAFormField = _
087 objAFormFields.Add("Header" & (i + 1), "text", _
088 i, (objAcroPoint.x / 2 - 100), _
089 (objAcroPoint.y - 15), _
090 (objAcroPoint.x / 2 + 100), _
091 (objAcroPoint.y - 35))
092
093 'テキストフィールドの各種設定
094 With objAFormField
095 .SetBackgroundColor "RGB", 1, 1, 1, 0
096 .Alignment = "center"
097 .TextFont = "HeiseiMin-W3-UniJIS-UCS2-H"
098 .Value = "Header " & Now() '表示する文字
099 .IsReadOnly = True '読み込み専用
100 .IsHidden = False '表示
101 End With
102
103 '設定後に開放
104 Set objAFormField = Nothing
105
106 Next
107
108 'PDFファイルを別名で保存
109 sFilePath_new = Replace(CON_FILEPATH, ".pdf", "_new.pdf")
110 bRet = objAcroPDDoc.Save(1, sFilePath_new)
111 If bRet = False Then
112 MsgBox "PDFファイルへ保存出来ませんでした", _
113 vbOKOnly vbCritical, "エラー"
114 bEnd = False
115 End If
116
117 'PDFファイルを閉じる
118 bRet = objAcroAVDoc.Close(1)
119 If bRet = False Then
120 MsgBox "AVDocオブジェクトはClose出来ませんでした", _
121 vbOKOnly vbCritical, "処理エラー"
122 bEnd = False
123 End If
124
125 Skip_AFormAut_Field_TextFont:
126 On Error Resume Next
127 '変更しないで閉じます。
128 bRet = objAcroAVDoc.Close(1)
129 'Acrobatアプリケーションの終了
130 objAcroApp.Hide
131 objAcroApp.Exit
132 'オブジェクトの開放
133 Set objAFormFields = Nothing
134 Set objAFormApp = Nothing
135 Set objAcroPDPage = Nothing
136 Set objAcroPoint = Nothing
137 Set objAcroPDDoc = Nothing
138 Set objAcroAVDoc = Nothing
139 Set objAcroApp = Nothing
140
141 If bEnd = True Then
142 MsgBox "処理は正常に終了しました。", _
143 vbOKOnly vbInformation, "正常終了"
144 End If
145 Exit Sub
146
147
148 '実行エラー(Runtime Error)
149 Err_AFormAut_Field_TextFont:
150 MsgBox Err.Number & vbCrLf & Err.Description, _
151 vbOKOnly vbCritical, "実行時のエラー"
152 bEnd = False
153 GoTo Skip_AFormAut_Field_TextFont:
154 End Sub
155
156 '*********************************************
157 ' メモリ上のAcrobatプロセスを数える。
158 '*********************************************
159 Private Function iCheckAcrobat() As Long
160 On Error GoTo skip_iCheckAcrobat: 'VBA実行時エラー
161 Dim items As Object
162 Set items = CreateObject("WbemScripting.SWbemLocator") _
163 .ConnectServer.ExecQuery( _
164 "Select * From Win32_Process " & _
165 "Where Name = 'Acrobat.exe'")
166 '1以上はプロセス有り、0は無し
167 iCheckAcrobat = items.Count
168 Exit Function
169 skip_iCheckAcrobat:
170 miErrorNo = Err.Number
171 msErrorMsg = Err.Description
172 End Function
173 '*********************************************
174 ' メモリ上に残ったAcrobatプロセスを
175 ' 正常に終了させる為だけの処理です。
176 '*********************************************
177 Sub EndAcrobat()
178 On Error Resume Next
179 Dim objAcroApp As New Acrobat.AcroApp
180 Dim objAcroAVDoc As New Acrobat.AcroAVDoc
181 Dim objAcroPDDoc As New Acrobat.AcroPDDoc
182 Dim objAcroPDPage As Acrobat.AcroPDPage
183 Dim objAcroPoint As Acrobat.AcroPoint
184 Dim objAFormApp As New AFORMAUTLib.AFormApp
185 Dim objAFormFields As AFORMAUTLib.Fields
186 Dim objAFormField As AFORMAUTLib.Field
187
188 objAcroApp.CloseAllDocs
189 objAcroApp.Hide
190 objAcroApp.Exit
191
192 Set objAFormField = Nothing
193 Set objAFormFields = Nothing
194 Set objAFormApp = Nothing
195 Set objAcroPoint = Nothing
196 Set objAcroPDPage = Nothing
197 Set objAcroPDDoc = Nothing
198 Set objAcroAVDoc = Nothing
199 Set objAcroApp = Nothing
200
201 '上記の実行後にメモリ上から消える、はず。
202 MsgBox "Acrobat OLEの終了を試みました。" & _
203 vbCrLf & "10秒後にメモリから消えたのを" & _
204 vbCrLf & "タスクマネージャーで確認して下さい。", _
205 vbSystemModal + vbInformation, "お知らせ"
206 End Sub
実行結果
Acrobat 7.1.4 実行時の結果
備考
- 特に無し。
注意
- 他の日本語フォントが既に PDFファイル に組み込まれていても使用は出来ません。
MS-Gothic : MS ゴシック
MS-Mincho : MS 明朝
MS-PGothic : MS Pゴシック
MS-PMincho : MS P明朝
- Field.Textfont = "MS-Mincho" を事項すると 実行エラー(Runtime Error) となる。
-2147467259 オートメーション エラーです。エラーと特定できません
- 更にこの後で強制的に AVDoc.close メソッドを実行すると以下が限りなく表示され、VBAが終了しなくなる。
別のプログラムでOLEの操作が完了するまで待機を続けます。
- 全OLEを実行する前に
objAcroApp.CloseAllDocs
で強制的にAcrobat アプリケーションをメモリ上にロードしないと
Set objAFormApp = CreateObject("AFormAut.App")
で実行エラー(ランタイムエラー)が発生する場合があります。
429 ActiveXコンポーネントはオブジェクトを作成できません。
動作確認の環境
- Acrobat 4.0 + Office 2000
+ Windows98SE( + WindowsUpdate) - Acrobat 5.0.5 + Office 2003( + SP3)
+ WindowsXP Pro( + SP3 + WindowsUpdate) - Acrobat 6.0.6 Pro + Office 2003( + SP3)
+ WindowsXP Pro( + SP3 + WindowsUpdate) - Acrobat 7.1.4 Pro + Office 2003( + SP3)
+ WindowsXP Pro( + SP2 + WindowsUpdate) - Acrobat 8.3.1 Pro + Office 2003( + SP3)
+ WindowsXP Pro( + SP3 + WindowsUpdate) - Acrobat 9.5.2 Extended + Office 2003( + SP3)
+ WindowsXP Pro( + SP3 + WindowsUpdate) - Acrobat X (10.1.4) Extended + Office 2003( + SP3)
+ WindowsXP Pro( + SP3 + WindowsUpdate) - Acrobat XI (11.0) Extended + Office 2003( + SP3)
+ WindowsXP Pro( + SP3 + WindowsUpdate)
Adobe Web 解説
OLE Automation / AFormAut / TextFont (公式サイト・英語)
< 戻る >
