excel - 从 Excel 运行 Word 宏
问题描述
我目前在 excel 中有一个宏,它允许我选择要打开的 word 文档,然后选择要导入的表。但是这个宏在excel中没有正确格式化表格,拆分单元格。理想情况下,我希望我可以修复这个宏,但我不知道如何。
Sub ImportWordTable()
Dim wdDoc As Object
Dim wdFileName As Variant
Dim TableNo As Integer 'table number in Word
Dim iRow As Long 'row index in Excel
Dim iCol As Integer 'column index in Excel
wdFileName = Application.GetOpenFilename("Word files ,*.doc;*.docx;*.docm", , _
"Browse for file containing table to be imported")
If wdFileName = False Then Exit Sub '(user cancelled import file browser)
Set wdDoc = GetObject(wdFileName) 'open Word file
With wdDoc
TableNo = wdDoc.TAbles.Count
If TableNo = 0 Then
MsgBox "This document contains no tables", _
vbExclamation, "Import Word Table"
ElseIf TableNo > 1 Then
TableNo = InputBox("This Word document contains " & TableNo & " tables." & vbCrLf & _
"Enter table number of table to import", "Import Word Table", "1")
End If
With .TAbles(TableNo).Range.Copy
Range("A1").Activate
Application.CommandBars.ExecuteMso "PasteSourceFormatting"
End With
End With
Set wdDoc = Nothing
End Sub
所以我有一个新脚本(在 Word 中),可以按照我想要的方式格式化表格并将其复制到剪贴板,并在 excel 中使用下一个宏从剪贴板粘贴。
无论如何,我想做的是:1)通过从excel中选择打开word文档2)一旦word文档打开,自动运行宏3)退出word并返回excel,我将在该系列中调用下一个宏。
有任何想法吗??
Sub RunWordMacroExe()
Dim oWFile As String
wdFileName = Application.GetOpenFilename("Word files ,*.doc;*.docx;*.docm", , _
"Browse for file containing table to be imported")
wordApp.ActiveDocument.CopyTableForExcel
End Sub
解决方案
推荐阅读
- python - 在 Jupyter 笔记本上找不到 Matplotlib
- node.js - 无法从 node.js express 上的 Angular HTTPClient 模块接收正文数据
- sql - Postgres - 如果提供的 user_id 的行不存在,则选择 user_id 为 NULL 的项目
- maven - python Flink安装找不到文件/flink-1.12-SNAPSHOT-bin/flink-1.12-SNAPSHOT/opt/flink-python_*.jar
- python - Python 枕头使我的 JPG 文件大 3 倍
- python - 结合两个 python 脚本,一个读取 IMU 另一个移动伺服电机
- java - java如何更新方法中的实例?
- java - 试图在 Java 中的 Scanner 用户输入中找到最小数字
- amazon-web-services - AWS CodeBuild:创建与我有权访问但不拥有它的 Bitbucket 存储库的连接
- elasticsearch - Elasticseach 重新索引 api 未重新索引所有文档