実現したいこと
在職証明のVBAのアプリを書きたいです。
ここに実現したいことを箇条書きで書いてください。
本日の日付を取得し 在職証明のwordに記載する。
イタリックテキスト
該当のソースコード
VBA
ソースコード
Private Sub ToggleButton1_Click()
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
'Wordアプリケーションを起動する
Set WordApp = CreateObject("Word.Application")
'既存のWordファイルを開く
Set WordDoc = WordApp.Documents.Open("C:\Users\boy_a\Downloads\zaishoku.docx")
'Word文書の最後にカーソルを移動
WordApp.Selection.EndKey Unit:=wdStory
'テキストボックスの値を取得
Dim zipCode As String
zipCode = TextBox1.Value
Dim address As String
address = TextBox2.Value
Dim name As String
name = TextBox3.Value
Dim birth As String
birth = TextBox4.Value
Dim shokui As String
name = TextBox6.Value
' WordTableの操作を追加する
Dim WordTable As Word.Table
Set WordTable = WordDoc.Tables(1)
With WordTable.Cell(1, 2).Range
.MoveEnd wdCharacter, -1
.InsertAfter Me.TextBox2.Value
End With
With WordTable.Cell(2, 2).Range
.MoveEnd wdCharacter, -1
.InsertAfter Me.TextBox3.Value
End With
With WordTable.Cell(3, 2).Range
.MoveEnd wdCharacter, -1
.InsertAfter Me.TextBox4.Value
End With
With WordTable.Cell(4, 2).Range
.MoveEnd wdCharacter, -1
.InsertAfter Me.TextBox6.Value
End With
Set WordTable = Nothing
'Wordの文書を保存して閉じる
WordDoc.Save
'Wordアプリケーションを終了する
WordApp.Quit
'オブジェクトを解放する
Set WordDoc = Nothing
Set WordApp = Nothing
End Sub
このプログラムに下記のような分を追記したいです。
' 本日の日付を取得
Dim currentDate As String currentDate = Format(Date, "yyyy年mm月dd日") ' ワードの下から8行目の右端に本日の日付を挿入する WordDoc.Content.Paragraphs.Last.Range.InsertAfter vbCrLf & Space(8) & currentDate
このプログラムを追記すると下の方に本日の日付が出るのですが
これを狙った位置に書きたいのです。

下から13行目の右端に記載し、できれば今の令和年月日という文字を削除し、記載したいのです。
画像の位置にある令和年月日の位置に書きたいです。
出来れば2023年ではなく令和の形式で書きたいのですが狙った位置に書くのやり方がわからず悩んでいます。
度々お聞きして申し訳ありませんが、解決可能な方いらっしゃったらご教示いただけませんでしょうか?

0 コメント