Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ms Word macros to Excel

Status
Not open for further replies.

acjeff

Programmer
Aug 10, 2004
148
0
0
US
Hi,

I am writing macros to copy data from Ms Word tables to Ms Excel. Here is my questions:

Before paste data onto Excel, I try to search for the last row on a worksheet.

Dim lastrow As Integer
lastrow = objExcelWorksheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row

When running, it shows variable not defined on xlPrevious and xlByRows. This code works on Excel macros but not on Word. How can I find the last row?

Jeff
 
Seems you use late binding so you have to define the needed predefined Excel constants or use their values:
lastrow = objExcelWorksheet.Cells.Find(What:="*", _
SearchDirection:=2, SearchOrder:=1).Row

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top