我是VBA for Mac的新用户,迄今为止没有留下深刻印象,甚至无法创建用户表单,这是我通常会完成此任务的方式。
我希望有消息框出现并向我询问信息,然后通过搜索和替换来填充多个实例。
例如,第一部分是要求文档作者,一旦msgbox有答案,它将替换文档中的字符串。
我尝试了很多不同的变体,但在前两个msgbox部分后的每种情况下我都会收到错误:
Sub auto_open()
Dim Author As String
Dim Title As String
Dim Longname As String
Dim Shortname As String
Dim Reference As String
Dim Createdate As String
Dim myStoryRange As Range
Author = InputBox(Prompt:="Enter your name here please.", _
Title:="Document Author", Default:="Your Name here")
With ActiveDocument.Content.Find
.Text = "<Document Author>"
.Replacement.Text = Author
.Execute Replace:=wdReplaceAll
.ClearFormatting
End With
Title = InputBox(Prompt:="Proposal, Maintenance Agreement etc?", _
Title:="Document Title", Default:="Proposal")
With ActiveDocument.Content.Find
.Text = "<Document Title>"
.Replacement.Text = Title
.Execute Replace:=wdReplaceAll
.ClearFormatting
End With
Longname = InputBox(Prompt:="Client's full legal name as per their ABN or ACN", _
Title:="Client's Full Name", Default:=" Pty Ltd")
With ActiveDocument.Content
.Find.Text = "<Long Customer Name>"
.Replacement.Text = Longname
.Execute Replace:=wdReplaceAll
.ClearFormatting
End With
Shortname = InputBox(Prompt:="Enter the usual name by which the client is known.", _
Title:="Client's short name or abbreviation", Default:=" ")
With ActiveDocument.Content
.Find.Text = "<Short Customer Name>"
.Replacement.Text = Shortname
.Execute Replace:=wdReplaceAll
.ClearFormatting
End With
Reference = InputBox(Prompt:="Use the number generated by Sales Force", _
Title:="Reference/Proposal number", Default:=" ")
With ActiveDocument.Content
.Find.Text = "<Reference Number>"
.Replacement.Text = Reference
.Execute Replace:=wdReplaceAll
.ClearFormatting
End With
Createdate = InputBox(Prompt:="Enter todays date or the date you will submit this proposal", _
Title:="Date document created", Default:=Now())
With ActiveDocument.Content
.Find.Text = "<Date Created>"
.Replacement.Text = Createdate
.Execute Replace:=wdReplaceAll
.ClearFormatting
End With
End Sub
正如你在这里看到的作者和标题的部分工作正常,但LongName
及以后的完全相同的代码没有?
(抱歉试图显示图片但尚不允许)
最终结果是,一旦代码到达LongName
,就会出错:
编译错误:
找不到方法或数据成员 (本文34:8)
答案 0 :(得分:0)
这是因为在前两种情况下,你有
With ActiveDocument.Content
但在随后的案例中你有
{{1}}
我希望With之后的第一行能够正常使用&#34; .Find.Text&#34;,但我不希望&#34; .Replacement.Text = ...& #34;生产线,因为它需要是&#34; .Find.Replacement.Text = ...&#34;