我有一个宏,它是为在一行上工作而编写的。我想在所有突出显示的行上运行这个宏。
有没有办法在选定的行之间循环并为每一行运行宏。
由于公司政策,我无法显示整个宏,但它基本上在 excel 中连续取值并将其填充到 word 模板中。这是宏的开始:
Sub OpenForm()
With Selection
Dim pappWord As Object
Dim docWord As Object
Dim wb As Excel.Workbook
Dim TodayDate As String
Dim Path As String
Set wb = ActiveWorkbook
TodayDate = Format(Date, "mmmm d, yyyy")
Path = wb.Path & "\MAF Template.dot"
On Error GoTo ErrorHandler
'Create a new Word Session
Set pappWord = CreateObject("Word.Application")
On Error GoTo ErrorHandler
'Open document in word
Set docWord = pappWord.Documents.Add(Path)
'Blank for Qty
docWord.FormFields("Text38").Result = Range(ActiveCell.EntireRow.Address)(1, 2) 'Part of System (System ID)
....它填充更多字段并以:
With pappWord
.Visible = True
.ActiveWindow.WindowState = 0
.Activate
End With
'Release the Word object to save memory and exit macro
ErrorExit:
Set pappWord = Nothing
Exit Sub
'Error Handling routine
ErrorHandler:
If Err Then
MsgBox "Error No: " & Err.Number & "; There is a problem"
If Not pappWord Is Nothing Then
pappWord.Quit False
End If
Resume ErrorExit
End If
End With
End Sub
所以它适用于单个 excel 行,而不是为每一行运行它,我想选择一些行并在所有行中运行宏。
谢谢,