Pulling in Data from Word
Okay, so I figured out how to do it, and it works pretty nicely, but I'd still be glad to hear of any possible improvements. One thing I couldn't figure out how to do was make Excel the active applicaton again after having opened the word document. I want Excel to be the application on screen while the macro is running. The only solution I could come up with was setting word visible = false. Any way to just "activate" excel
Public Sub test(
Dim wd As Objec
Dim tempvar As Strin
Dim xlapp As Excel.Applicatio
Dim wdAPP As Word.Applicatio
Dim wdDoc As Word.Documen
Dim response As VbMsgBoxResul
Set xlapp = Excel.Applicatio
sRNM = Application.GetOpenFilename("Word Files (*.doc), *.doc"
If sRNM = False The
GoTo e
End I
' With Dialogs(xlDialogFileOpen
' If .Display The
' sRNM = WordBasic.FilenameInfo$(.Name, 1
' End I
' End Wit
Set wdAPP = CreateObject("Word.Application"
Set wdDoc = wdAPP.Documents.Open(sRNM
wdAPP.Visible = Fals
For i = 2 To 100
xlapp.Goto Reference:=Rows(i).Columns("B"
tempvar = Application.Selectio
With wdAPP.Selection.Fin
.ClearFormattin
.MatchWildcards = Fals
.MatchCase = Tru
.Forward = Tru
.Wrap = wdFindContinu
.Text = tempva
.Execut
End Wit
If wdAPP.Selection.Find.found = True The
With wdAPP.Selectio
.MoveLeft unit:=wdCell, Count:=
.selectcel
.Cop
End Wit
xlapp.Goto Reference:=Rows(i).Columns("A"
tempvar2 = Application.Selectio
If tempvar2 < "" The
response = MsgBox("There is already an ID here! Continue Running?", vbYesNo
If response = vbNo The
wdAPP.Quit savechanges = Fals
GoTo e
End I
Els
xlapp.ActiveSheet.Paste Destination:=Rows(i).Columns("A"
End I
End I
Nex
wdAPP.Visible = Tru
wdAPP.Quit savechanges = Fals
Set wdAPP = Nothin
Set wdDoc = Nothin
es
End Su
|