Hi,
I'm very new to VBA. I'm using it to try to create an Excel spreadsheet out of specific pieces of information extracted from a 100-page microsoft word document. This is what I have so far:
Sub GrabUsage()Dim FName As String, FD As FileDialog
Dim WApp As Object, WDoc As Object, WDR As Object
Dim ExR As Range
Set ExR = Selection ' current location in Excel Sheet
Set FD = Application.FileDialog(msoFileDialogOpen)
FD.Show
If FD.SelectedItems.Count <> 0 Then
FName = FD.SelectedItems(1)
Else
Exit Sub
End If
Set WApp = CreateObject("Word.Application")
' WApp.Visible = True
Set WDoc = WApp.Documents.Open(FName)
WApp.Selection.HomeKey Unit:=6
WApp.Selection.Find.ClearFormatting
WApp.Selection.Find.Execute "Updated"
WApp.Selection.MoveDown Unit:=5, Count:=1
WApp.Selection.MoveRight Unit:=2, Count:=15, Extend:=1
Set WDR = WApp.Selection
ExR(1, 1) = WDR ' place at Excel cursor
WApp.Selection.HomeKey Unit:=6
WApp.Selection.Find.ClearFormatting
WApp.Selection.Find.Execute "NICU Beds"
WApp.Selection.MoveRight Unit:=2, Count:=2
WApp.Selection.MoveRight Unit:=2, Count:=1, Extend:=1
Set WDR = WApp.Selection
ExR(1, 2) = WDR ' place in cell right of Excel cursor
WDoc.Close
WApp.Quit
End Sub
This gets me the first string of words after Updated and NICU Beds, but I want all the instances of the word strings following those words. How can I get the macro to find all of them and put them each in their own cell?
I'm very new to VBA. I'm using it to try to create an Excel spreadsheet out of specific pieces of information extracted from a 100-page microsoft word document. This is what I have so far:
Sub GrabUsage()Dim FName As String, FD As FileDialog
Dim WApp As Object, WDoc As Object, WDR As Object
Dim ExR As Range
Set ExR = Selection ' current location in Excel Sheet
Set FD = Application.FileDialog(msoFileDialogOpen)
FD.Show
If FD.SelectedItems.Count <> 0 Then
FName = FD.SelectedItems(1)
Else
Exit Sub
End If
Set WApp = CreateObject("Word.Application")
' WApp.Visible = True
Set WDoc = WApp.Documents.Open(FName)
WApp.Selection.HomeKey Unit:=6
WApp.Selection.Find.ClearFormatting
WApp.Selection.Find.Execute "Updated"
WApp.Selection.MoveDown Unit:=5, Count:=1
WApp.Selection.MoveRight Unit:=2, Count:=15, Extend:=1
Set WDR = WApp.Selection
ExR(1, 1) = WDR ' place at Excel cursor
WApp.Selection.HomeKey Unit:=6
WApp.Selection.Find.ClearFormatting
WApp.Selection.Find.Execute "NICU Beds"
WApp.Selection.MoveRight Unit:=2, Count:=2
WApp.Selection.MoveRight Unit:=2, Count:=1, Extend:=1
Set WDR = WApp.Selection
ExR(1, 2) = WDR ' place in cell right of Excel cursor
WDoc.Close
WApp.Quit
End Sub
This gets me the first string of words after Updated and NICU Beds, but I want all the instances of the word strings following those words. How can I get the macro to find all of them and put them each in their own cell?