2017-07-17 3 views
0

次のエラーを出す単語ファイルの場所を開こうとしています。デバッグ中に私は次の場所にエラーが見つかりました。私はVBAのためnewbee誰かが私を助けることができています単語ファイルの検索でエラーを解決するにはどうすればよいですか?

enter image description here

私のコードは、その定義にnewを追加したり、後で新しいとして設定作成されていない

sub findBearingCopyFromExcel() 
    Dim i As Integer 
    Dim aCell As Range, rng As Range 
    Dim SearchString As String 
Set rng = Range("A750:A1790") 
SearchString = "(248_R), 38,7 %" 

For Each aCell In rng 
    If InStr(1, aCell.Value, SearchString, vbTextCompare) Then 
     ActiveSheet.Range(Cells(aCell.row + 4, 1), Cells(aCell.row + 9, 6)).Copy 
Exit Sub 
     Else: End If 
    Next aCell 
End Sub 
Sub bearingDataFromExcelToWord() 
Dim wrdApp As Word.Application 
Dim wdoc As Word.Document 
Set wdoc = wrdApp.Documents.Open("E:\ShareDrive_Ruehl\full-flexible-MBS-models_report\example-report\FullFlexibleGearbox - Copy.docx") 

wrdApp.Visible = True 
With wdoc 
.Application.Selection.Find.Text = "(248_R), 38,7 %" 
.Application.Selection.Find.Execute 


.Application.Selection.MoveDown Unit:=wdLine, Count:=1 
    .Application.Selection.EndKey Unit:=wdLine 
    .Application.Selection.EndKey Unit:=wdLine 
    .Application.Selection.MoveRight Unit:=wdCharacter, Count:=1 
    .Application.Selection.EndKey Unit:=wdLine 
    .Application.Selection.MoveDown Unit:=wdLine, Count:=6, Extend:=wdExtend 
    .Application.Selection.MoveLeft Unit:=wdCharacter, Count:=5, Extend:=wdExtend 
    .Application.Selection.Paste 
    End With 
End Sub 
+0

サイドノートをチェックし :常に文字コードブロックとしてコードを埋め込むしてください(ない画像など)、人ので、簡単にコピーして修正できます。 –

+0

@Pehフィードバックに感謝します。私もコードを追加しました。私はちょうど私がエラーを見つけた場所とエラーボックスを表示したかっただけです。この訂正が私の問題を解決するのに役立つかどうかご連絡ください。 :) –

答えて

0

wrdAppですが、使用する前にそれ。

+0

ありがとう@Nathan_Sav。今、別のエラーが発生しています。 "Microsoft Excelは、別のアプリケーションがOLEアクションを完了するのを待っています"。それが何であるかを確認できますか? –

0

wrdAppのインスタンスを作成する必要があります。

Dim wrdApp As Word.Application 
Set wrdApp = New Word.Application 
    wrdApp.Visible = True 

Dim wdoc as Word.Document 
Set wdoc = wrdApp.Documents.Open(...) 
+0

ありがとう、私はそのエラーを解決するのに役立ちます。しかし今、別のエラーが発生しています。 "Microsoft Excelは別のアプリケーションがOLEアクションを完了するのを待っています" –

0

ドキュメントを開くときに掛かっていると思われます。正しいパスとファイル名を使用してください。 「Wdocを設定...」の行の前に

wrdApp.Visible = True 

を移動し、ファイルを開いた場合

+0

はい。 @ハラズドパッド。場所は正しいです。私は、URの提案を試みた。しかし、 "定義されていないユーザー定義型"として表示されています。コンパイルエラー –

+0

コンパイルエラーが発生したときに強調表示される行は何ですか? –

+0

私はさらに働き、この結果を得ました。あなたはこの問題を見ていただけますか? https://stackoverflow.com/questions/45275980/how-to-insert-data-copied-from-an-excel-sheet-to-the-table-existing-in-the-word –

関連する問題