我想打開它給出以下錯誤的文件的位置。在調試過程中,我在以下位置找到了錯誤。我newbee的VBA有人可以幫助我如何解決定位文件中的錯誤?
我的代碼是
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
邊注:請始終嵌入的代碼作爲文本代碼塊(而不是圖像),所以人們可以很容易地複製和修復它。 –
@Peh感謝您的反饋。我也添加了代碼。我只想顯示我發現錯誤的位置以及錯誤框。請讓我知道這個更正是否可以幫助我解決我的問題。 :) –