0

我正在研究一个宏,它有3个问题。可能更多取决于您的程序员经验。我正在尝试让我的代码立即执行此操作。

在代码的底部,我试图使输入框工作,以便用户的输入将成为“Assigned BK Specialist:”的替换文本

With ActiveDocument.Content.Find
    .Text = "Assigned BK Specialist:"
    .Replacement.Text = InputBox("Type in BK specialist's name.", "Mark Scott")
End With

Sub Combined_Code()
'Condense Version
Dim iRet As Integer
Dim strPrompt As String
Dim strTitle As String
Dim BkSpecName As String

For i = 1 To 2
With Selection.Find
    .Text = "date received"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindAsk
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
End With
Selection.Find.Execute
Selection.Paste
Selection.MoveDown Unit:=wdLine, Count:=10
Next i
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="3"
Selection.Find.Replacement.ClearFormatting
'   Insert your name for the file.
With Selection.Find
    .Text = "By:"
End With
Selection.Find.Execute
Selection.TypeText Text:="By: Robert Birch"
With Selection.Find
    .Text = "Date Assigned:"
End With
'   Insert current date on 3rd page.
Selection.Find.Execute
Selection.TypeText Text:="Date Assigned: "
Selection.InsertDateTime DateTimeFormat:="M/d/yyyy", InsertAsField:=False, _
    DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
    InsertAsFullWidth:=False

'Prompt
strPrompt = "What chapter is the MFR for?, NO = 13, Yes = 7"

'Dialog's Title
strTitle = "What Chapter Are You Working On?"

'Display MessageBox
iRet = MsgBox(strPrompt, vbYesNoCancel, strTitle, Yes = "Option1", No = "Option2")

'Check pressed button
If iRet = vbNo Then
    MsgBox "Running Ch.13!"
'   Added code for ch 13
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.MoveDown Unit:=wdLine, Count:=9
Selection.MoveRight Unit:=wdCell, Count:=2
    For q = 1 To 7
        Selection.TypeText Text:="x"
        Selection.MoveDown Unit:=wdLine, Count:=1
    Next q
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="2"
Selection.MoveDown Unit:=wdLine, Count:=10
Selection.MoveRight Unit:=wdCell, Count:=2
    For w = 1 To 9
        Selection.TypeText Text:="x"
        Selection.MoveDown Unit:=wdLine, Count:=1
    Next w
Else
    MsgBox "Running Ch.7!"
' Added coded for Ch.7
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.MoveDown Unit:=wdLine, Count:=9
Selection.MoveRight Unit:=wdCell, Count:=2
For b = 1 To 7
Selection.TypeText Text:="x"
Selection.MoveDown Unit:=wdLine, Count:=1
'modded
Next b
        Selection.MoveDown Unit:=wdLine, Count:=10
For j = 1 To 3
        Selection.TypeText Text:="x"
        Selection.MoveDown Unit:=wdLine, Count:=1
Next j
        Selection.TypeText Text:="n/a"
        Selection.MoveDown Unit:=wdLine, Count:=1
        Selection.TypeText Text:="n/a"
For o = 1 To 4
      Selection.MoveDown Unit:=wdLine, Count:=1
      Selection.TypeText Text:="x"
Next o
End If
 Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="3"
    Selection.MoveDown Unit:=wdLine, Count:=9
    Selection.MoveRight Unit:=wdCell, Count:=2
    Selection.TypeText Text:="x"
    Selection.MoveDown Unit:=wdLine, Count:=2
    Selection.TypeText Text:="x"
'End part of program requires user input for BK spec's name
With ActiveDocument.Content.Find
         .Text = "Assigned BK Specialist:"
         .Replacement.Text = InputBox("Type in BK specialist's name.", "Mark Scott")
End With
4

1 回答 1

0

试试这样:

With ActiveDocument.Content.Find
         .Text = "Assigned BK Specialist:"
         .Replacement.Text = InputBox("Type in BK specialist's name.", "Mark Scott")
         .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue '<----- add that
End With
于 2013-04-10T04:04:01.117 回答