nasserlouis
2017-08-17, 20:16
لدي مشكله مع code macro MS word file
لدي برنامج يمسح الاسطر ذات المحتوى الفارغ يعمل جيدا مع جدول في الوورد
لكنه يمسح بعض الاسطر التي لا اريد مسحها هل من طريقه لتفادي مسح بعض الاسطر عددها 8 فقط
VBA code :
Sub DeleteBlankTableRows()
Dim deleted As Boolean
Dim oRow As Row
deleted = False
On Error Resume Next
ActiveDocument.Tables(1).Select
If Selection.Information(wdWithInTable) = False Then
MsgBox "No table exists in the document!", vbCritical, "Error"
Exit Sub
End If
For Each oRow In Selection.Tables(1).Rows
If oRow Is Nothing Then
MsgBox "The tool cannot work in this table. This might be because one or more rows have merged cells. If these merged cells are removed, it will probably work.", _
vbCritical, "Error"
End
End If
If Len(oRow.Cells(2).Range.Text) = 2 Then
'Or If InStr(oRow.Range.Text, "") > 0 Then
oRow.Delete
deleted = True
End If
Next oRow
If deleted Then
MsgBox "All Blank lines have been deleted.", vbOKOnly, "Success!"
Else
MsgBox "No Blank lines containing *To Be Deleted* text can be found.", vbOKOnly, "Failure!"
End If
End Sub
لدي برنامج يمسح الاسطر ذات المحتوى الفارغ يعمل جيدا مع جدول في الوورد
لكنه يمسح بعض الاسطر التي لا اريد مسحها هل من طريقه لتفادي مسح بعض الاسطر عددها 8 فقط
VBA code :
Sub DeleteBlankTableRows()
Dim deleted As Boolean
Dim oRow As Row
deleted = False
On Error Resume Next
ActiveDocument.Tables(1).Select
If Selection.Information(wdWithInTable) = False Then
MsgBox "No table exists in the document!", vbCritical, "Error"
Exit Sub
End If
For Each oRow In Selection.Tables(1).Rows
If oRow Is Nothing Then
MsgBox "The tool cannot work in this table. This might be because one or more rows have merged cells. If these merged cells are removed, it will probably work.", _
vbCritical, "Error"
End
End If
If Len(oRow.Cells(2).Range.Text) = 2 Then
'Or If InStr(oRow.Range.Text, "") > 0 Then
oRow.Delete
deleted = True
End If
Next oRow
If deleted Then
MsgBox "All Blank lines have been deleted.", vbOKOnly, "Success!"
Else
MsgBox "No Blank lines containing *To Be Deleted* text can be found.", vbOKOnly, "Failure!"
End If
End Sub