VBA文档关闭帮助请 [英] VBA Document Close Help Please
问题描述
我有一个word文档,里面有"I,Student Name"字样。我试图写一个代码,以便当用户关闭文件时,一个b
输入框提示他们并要求用户输入他们的名字,我输入
鲍勃史密斯,它用比特史密斯替换学生姓名,然后关闭
但是当我再次打开文件时,它有bob smith,这就是我的
想。但当我关闭文件时,它再次要求提供这个名字。
$
我怎么能这样做呢?当它已经有了这个人的名字时,它又不再要求这个
的名字?
我所拥有的代码如下所示
感谢高级
PS我正在使用Microsoft Word
Private Sub Document_Close()
Dim rng As Range
Set rng = ThisDocument.Content
rng.Find.Execute" student name",False ,,,,,,,, InputBox("输入你的名字"),wdReplaceAll
ThisDocument.Save
End Sub
你可以使用
Private Sub Document_Close()
Dim rng As Range
Set rng = ThisDocument.Content
如果rng.Find.Execute(" Student Name")则
rng.Text = InputBox("输入你的姓名")
结束如果
ThisDocument.Save
End Sub
Hi,
I have a word document that has in it the words "I, Student Name" and i
am trying to write a code so that when the user closes the document a
input box prompts them and asks the user to enter their name for i enter
Bob Smith and it replaces Student name with Bit Smith and then closes
but when i open the document again it has bob smith which is what i
want. But when i go to close the document
it asks for the name again. How can i make it so it doesnt ask for the
name again when it already has the name of the person it in?
the code i have is below here
thanks in advanced
P.S i am using Microsoft Word
Private Sub Document_Close() Dim rng As Range Set rng = ThisDocument.Content rng.Find.Execute "student name", False, , , , , , , , InputBox("Enter Your Name"), wdReplaceAll ThisDocument.Save End Sub
You could use
Private Sub Document_Close() Dim rng As Range Set rng = ThisDocument.Content If rng.Find.Execute("Student Name") Then rng.Text = InputBox("Enter Your Name") End If ThisDocument.Save End Sub
这篇关于VBA文档关闭帮助请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!