Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.54 KB | None | 0 0
  1. Sub ExamineSpecific()
  2.  
  3. 'Dim bRun As Boolean
  4.    
  5. 'Use our workbook
  6. Dim wbk As Workbook
  7. Dim wks As Worksheet
  8. Set wbk = ThisWorkbook
  9. Set wks = wbk.Worksheets(3)
  10. Set wps = wbk.Worksheets(2)
  11.  
  12. wbk.Activate
  13. wks.Activate
  14. wks.Range("A1").Select
  15. Selection.End(xlDown).Select
  16. With ActiveCell
  17.     endrow = .Row
  18. End With
  19.  
  20.  
  21. 'Initialize variables
  22. Dim wdApp As Word.Application
  23. Dim wdDoc As Word.Document
  24. Dim wdCell As Word.Cell
  25. Set wdApp = New Word.Application
  26. Dim lTable, lRow, lColumn As Long
  27.  
  28.  
  29.  
  30. Dim MyDialog As FileDialog, GetStr(1 To 100) As String '100 files is the maximum applying this code
  31. On Error Resume Next
  32. Set MyDialog = Application.FileDialog(msoFileDialogFilePicker)
  33. With MyDialog
  34. .Filters.Clear
  35. .Filters.Add "All WORD File ", "*.doc*", 1
  36. .AllowMultiSelect = True
  37. i = 1
  38. If .Show = -1 Then
  39. For Each stiSelectedItem In .SelectedItems
  40. GetStr(i) = stiSelectedItem
  41. i = i + 1
  42. Next
  43. i = i - 1
  44. End If
  45. 'Application.ScreenUpdating = False
  46.  
  47. For j = 1 To i Step 1
  48.  
  49. Set wdDoc = wdApp.Documents.Open(GetStr(j))
  50. wdApp.Visible = True
  51.  
  52. For r = 1 To endrow Step 1
  53.     lTable = wps.Cells(r, 1).Value
  54.     lRow = wps.Cells(r, 2).Value
  55.     lColumn = wps.Cells(r, 3).Value
  56.     wks.Cells(r, j + 1) = Left(wdDoc.Tables(lTable).Cell(lRow, lColumn).Range.Text, Len(wdDoc.Tables(lTable).Cell(lRow, lColumn).Range.Text) - 1)
  57. Next r
  58. wks.Cells(r + 1, j + 1) = wdDoc.Name
  59. wdDoc.Close SaveChanges:=False
  60. Set wdCell = Nothing
  61. Set wdDoc = Nothing
  62. Next j
  63. End With
  64.  
  65. Set wdApp = Nothing
  66.  
  67. Application.ScreenUpdating = True
  68.  
  69.  
  70. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement