J
Joel
I'm trying to understand differences between excel and word macros. Trying to
get Last sentence before first table in a document. I got the word macro to
run correctly. I tried applying same code to Excel macro and MoveUp fails.
I posted both macro below. Can somebody explain?????????????????
Word Macro - Works Correctly
-----------------------------------------------------------
Sub getlastline()
With ActiveDocument
Set FirstTable = .Tables(1)
Set FirstCell = FirstTable.Rows(1).Cells(1)
FirstCell.Select
Selection.MoveUp unit:=wdLine, Count:=1
Selection.Move unit:=wdSentence, Count:=-1
Selection.Sentences(1).Select
End With
End Sub
Excel Code - Move Up fails
----------------------------------------------------------------
Sub getlastline()
Set WdObj = CreateObject("Word.Application")
WdObj.Visible = True
Set WDDoc = WdObj.Documents.Open(Filename:="c:\temp\table test.doc")
With WDDoc
Set FirstTable = .Tables(1)
Set FirstCell = FirstTable.Rows(1).Cells(1)
FirstCell.Select
Selection.MoveUp unit:=wdLine, Count:=1
Selection.Move unit:=wdSentence, Count:=-1
Selection.Sentences(1).Select
End With
End Sub
get Last sentence before first table in a document. I got the word macro to
run correctly. I tried applying same code to Excel macro and MoveUp fails.
I posted both macro below. Can somebody explain?????????????????
Word Macro - Works Correctly
-----------------------------------------------------------
Sub getlastline()
With ActiveDocument
Set FirstTable = .Tables(1)
Set FirstCell = FirstTable.Rows(1).Cells(1)
FirstCell.Select
Selection.MoveUp unit:=wdLine, Count:=1
Selection.Move unit:=wdSentence, Count:=-1
Selection.Sentences(1).Select
End With
End Sub
Excel Code - Move Up fails
----------------------------------------------------------------
Sub getlastline()
Set WdObj = CreateObject("Word.Application")
WdObj.Visible = True
Set WDDoc = WdObj.Documents.Open(Filename:="c:\temp\table test.doc")
With WDDoc
Set FirstTable = .Tables(1)
Set FirstCell = FirstTable.Rows(1).Cells(1)
FirstCell.Select
Selection.MoveUp unit:=wdLine, Count:=1
Selection.Move unit:=wdSentence, Count:=-1
Selection.Sentences(1).Select
End With
End Sub