以下是 VBA 代码示例,用于打印文件夹中选定的部分 Word 文档:
```
Sub PrintSelectedDocuments()
    ' 获取选中的文件路径
    Dim folderPath As String
    folderPath = Application.FileDialog(msoFileDialogFolderPicker).Show
    
    ' 如果用户取消选择文件夹,则退出过程
    If folderPath = "" Then Exit Sub
    
    ' 遍历文件夹中的所有文件
    Dim fileName As String
    Dim filePath As String
    Dim doc As Document
    For Each fileName In FileSystem.GetFiles(folderPath)
        filePath = folderPath & "\" & fileName
        
        ' 检查文件是否为 Word 文档
        If Right(filePath, 4) = ".doc" Or Right(filePath, 5) = ".docx" Then
            ' 打开文档并检查是否选中
            Set doc = Documents.Open(filePath)
            If Selection.Range.InRange(doc.Range) Then
                ' 如果选中,则打印文档
                doc.PrintOut
            End If
            doc.Close
        End If
    Next fileName
End Sub
```
在这个示例中,我们首先创建了一个名为 `PrintSelectedDocuments` 的过程,用于打印选定的文件夹中的 Word 文档。我们使用 `Application.FileDialog` 方法显示文件夹选择对话框,并使用 `FileSystem.GetFiles` 方法遍历文件夹中的所有文件。
对于每个文件,我们检查其扩展名是否为 `.doc` 或 `.docx`,以确定它是否为 Word 文档。如果是 Word 文档,则使用 `Documents.Open` 方法打开文档,并使用 `Selection.Range.InRange`