Hello Everyone!
I have this simple problem and I'm wondering if there is a way to get a textbox value to a Ms word template.
For example my textbox contains the current date and I wanted to get that value to my ms word.
I wanted to replace my MS word #Date# to the textbox value and so on..
I have provided a screenshot and code.
Hoping someone can help me solve this one. Thank you!
I have this simple problem and I'm wondering if there is a way to get a textbox value to a Ms word template.
For example my textbox contains the current date and I wanted to get that value to my ms word.
I wanted to replace my MS word #Date# to the textbox value and so on..
I have provided a screenshot and code.
Hoping someone can help me solve this one. Thank you!
VBA Code:
FilePath = "D:\" & Me.ComboBox1 & "_" & Me.TextBox4 & ".pdf"
On Error Resume Next
Kill FilePath
DocFile = "D:\PHOTO\Sample.docx" 'Template File
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Set WordApp = New Word.Application
Set WordDoc = WordApp.Documents.Open(DocFile, False)
Word.Application.Visible = True
With WordDoc.Content.Find
.Text = "#" & Me("Label").Caption & "#"
.Replacement.Text = Me("Textbox").Value
.Execute Replace:=wdReplaceAll
End With
WordDoc.ExportAsFixedFormat OutputFileName:=FilePath, ExportFormat:=wdExportFormatPDF
WordDoc.Close saveChanges:=False
WordApp.Quit
Set WordApp = Nothing
Set WordDoc = Nothing
MsgBox "Success!"