subfolderearch_1level

2
Public Sub EXTRACT()  Dim xl As Object  Dim xl2 As Object  Dim fso As New FileSystemObject  Dim f As Folder, SubFolders As Folders Set xl = CreateObject("word.app lication")  Set xl2 = CreateObject("excel.application")  xl.documents.Add  'xl2.Workbooks.Add  xl.Visible = True  xl2.Visible = True 'Dim c As Integer 'c = 1 Dim circuit As String circuit = "Y:\YANPET 2\UNIT-210\Piping-210\RBI PIPING\RBI PIPING 2015" circuit = Application.ActiveWorkbo ok.Path Set f = fso.GetFolder(circuit) 'Sheet1.Range(A2:d1450).Clear Sheet1.Range("A2:D1480").Value = ""  Set SubFolders = f.SubFolders strFolders = "" xlC = 1 xlR = 2 For Each f In SubFolders  On Error Resume Next  strFolders = f.Name  On Error Resume Next strFolders = strFolders & "\"  On Error Resume Next  'Here put your path where you have your documents to read:  myPath = circuit & "\" & strFolders 'End with '\'  myFile = Dir(myPath & "*.docx")  On Error Resume Next 'Sheet1.Cells(c, 1) = myPath 'c = c + 1  On Error Resume Next  Do While myFile <> ""  On Error Resume Next  xl.documents.Open Filename:=myPath & myFile, ReadOnly:=True  xlTRC = 2  On Error Resume Next  myCL = xl.ActiveDocument.Tables(1).Cell(3, 2).Range.Text  On Error Resume Next  'xl2.ActiveWorkbook.ActiveSheet.Cells(xlR, 1) = myCL  Sheet1.Cells(xlR, 1) = myCL  On Error Resume Next

description

vba code word extract

Transcript of subfolderearch_1level

Page 1: subfolderearch_1level

7/17/2019 subfolderearch_1level

http://slidepdf.com/reader/full/subfolderearch1level 1/2

Public Sub EXTRACT()  Dim xl As Object  Dim xl2 As Object  Dim fso As New FileSystemObject  Dim f As Folder, SubFolders As Folders

  Set xl = CreateObject("word.application")  Set xl2 = CreateObject("excel.application")

  xl.documents.Add  'xl2.Workbooks.Add  xl.Visible = True  xl2.Visible = True'Dim c As Integer'c = 1Dim circuit As String

circuit = "Y:\YANPET 2\UNIT-210\Piping-210\RBI PIPING\RBI PIPING 2015"circuit = Application.ActiveWorkbook.PathSet f = fso.GetFolder(circuit)

'Sheet1.Range(A2:d1450).ClearSheet1.Range("A2:D1480").Value = ""

 Set SubFolders = f.SubFolders

strFolders = ""

xlC = 1xlR = 2

For Each f In SubFolders  On Error Resume Next  strFolders = f.Name  On Error Resume Next  strFolders = strFolders & "\"

  On Error Resume Next  'Here put your path where you have your documents to read:  myPath = circuit & "\" & strFolders 'End with '\'  myFile = Dir(myPath & "*.docx")  On Error Resume Next

'Sheet1.Cells(c, 1) = myPath'c = c + 1

 On Error Resume Next  Do While myFile <> "" 

On Error Resume Next  xl.documents.Open Filename:=myPath & myFile, ReadOnly:=True  xlTRC = 2  On Error Resume Next  myCL = xl.ActiveDocument.Tables(1).Cell(3, 2).Range.Text  On Error Resume Next  'xl2.ActiveWorkbook.ActiveSheet.Cells(xlR, 1) = myCL 

Sheet1.Cells(xlR, 1) = myCL  On Error Resume Next

Page 2: subfolderearch_1level

7/17/2019 subfolderearch_1level

http://slidepdf.com/reader/full/subfolderearch1level 2/2

  myCL = xl.ActiveDocument.Tables(1).Cell(4, 2).Range.Text  On Error Resume Next  Sheet1.Cells(xlR, 2) = myCL  On Error Resume Next  myCL = xl.ActiveDocument.Tables(2).Cell(12, 2).Range.Text  Sheet1.Cells(xlR, 3) = myCL  On Error Resume Next  myCL = xl.ActiveDocument.Tables(5).Cell(2, 1).Range.Text  On Error Resume Next  myCL = ""  Do While xlTRC <= xl.ActiveDocument.Tables(5).Rows.Count  On Error Resume Next  myCL = myCL & xl.ActiveDocument.Tables(5).Cell(xlTRC, 1).Range.Text  On Error Resume Next  xlTRC = xlTRC + 1  Loop  On Error Resume Next  Sheet1.Cells(xlR, 4) = myCL  On Error Resume Next  xlR = xlR + 1  myCL = ""  On Error Resume Next  xl.ActiveWindow.Close False

  On Error Resume Next  myFile = Dir On Error Resume Next

  Loop  On Error Resume NextNext

  xl.Visible = False  xl2.Visible = True  xl.Quit  Set xl = Nothing 

End Sub

Private Sub CommandButton1_Click()CommandButton1.BackColor = vbRed  Call EXTRACTCommandButton1.BackColor = vbGreenEnd Sub