首次发布,请轻松一下...... 我编写了一些代码来替换Word模板中的占位符文本,以及来自Excel文件的文本。 (例如,将所有出现的Business_Name替换为Buddy' s Dog Grooming)代码运行,并按计划替换所有内容,但是当使用Excel中的货币$ 100,000替换Word文本Total_FMV时,代码会吐出100000。有关如何让Word中的文本读取100,000美元而没有小数的任何想法?
Private Sub OnSite_Builder_Click()
Template = "C:\Users\Me\Desktop\TEMPLATE.docx"
Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Open(Template, ReadOnly:=True)
wrdApp.Visible = True
wrdApp.Selection.Find.ClearFormatting
wrdApp.Selection.Find.Replacement.ClearFormatting
'Total FMV
With wrdApp.Selection.Find
.Text = "Total_FMV"
.Replacement.Text = Range("C28")
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wrdApp.Selection.Find.Execute Replace:=wdReplaceAll
End Sub
答案 0 :(得分:0)
您可以将:.Replacement.Text = Range(“C28”)替换为:
.Replacement.Text = Range("C28").NumberFormat = "$#,###"
答案 1 :(得分:0)
尝试
.Replacement.Text =Format(Range("C28"),"$#,##0")