我正在Excel(2010)中编写一个宏来从Word(2010)复制3个书签的值并将它们粘贴到某个Excel范围中。
我在这里和其他各种论坛上发现了几个类似的问题,但是大多数是Word中的宏,并且没有正确的参考资料来满足我的需要。
请注意我将使用此功能从多个文档(大约200个)中获取名称,日期和整数,这些文档都具有相同的书签。这将在不同的时间运行,具体取决于我何时评估文档的内容并将其标记为已完成。
快速了解宏应该做什么:
这是我当前的代码(以下是我的问题列表):
Private Sub cmdImport_Click()
Dim intDocCount As Integer
Dim wdApp As Word.Application, wdDoc As Word.Document, xlWb As Excel.Workbook, xlWs As Excel.Worksheet
Set wdApp = Word.Application
Set wdDoc = ActiveDocument
Set xlWb = ThisWorkbook 'Edited from ActiveWorkbook
Set xlWs = ActiveWorkbook.Sheets("Sheet1")
intDocCount = Word.Application.Documents.Count
If intDocCount = 1 Then
GoTo Import
ElseIf intDocCount > 1 Then
MsgBox "There are " & intDocCount & " Word Documents open." & vbNewLine & vbNewLine & _
"Please close the additional MS Word Documents", vbCritical, "Too many Word Documents open!"
Exit Sub
ElseIf intDocCount < 1 Then 'Currently shows Runtime Error 462 rather than MsgBox
MsgBox "There are no MS Word Documents open.", vbInformation, "No Word Documents open"
Exit Sub
End If
Import:
With wdApp
wdDoc.Activate
wdDoc.Bookmarks("test").Range.Select
wdDoc.Copy 'Run-time error '438' here
End With
With xlWb
xlWs.Activate
xlWs.Cells(2, 1) = Selection
xlWs.Paste
End With
End Sub
因此,如代码所示,第二个ElseIf
语句返回运行时错误'462'“远程服务器计算机不存在或不可用”而不是vbInformation
消息,
AND
只要有1个单词文件打开,我会收到以下内容:
“运行时错误'13':类型不匹配”。
wdDoc.Copy
行
Unfortunatley我还没有找到任何其他问题/答案来涵盖这个特定场景,也没有让Frankenstein能够一起编写代码。
编辑: Set xlWb = ThisWorkbook
已从修复运行时错误“13”的Set xlWb = ActiveWorkbook
更改。
添加了有关运行时错误“438”的信息。
答案 0 :(得分:1)
请这样试试......
//Confirm Order
public function confirmOrder(Request $request) {
$id = $request->get('id');
$name = $request->get('name');
$position = $request->get('position');
$response = (new GuzzleHttp\Client)->post(getenv('API_MICRO_URL') . '/orders/send/copy', [
'form_params' => [
'id' => $id,
'name' => $name,
'position' => $position
],
'headers' => [
'Authorization' => 'Bearer '.session()->get('token.access_token'),
'Accept' => 'application/json',
]
]);
return response('all signed up');
}
}