1

I wrote succesully in Visual Foxpro the research of the Workbooks in a specific customer's directory and subdir. Now I want, starting by the first Workbook, append the the second just below the first and so on... I wrote, attempting to have success:

xStrFName = TRIM(filemm)
oExcel.Workbooks.Open(xStrFName)
oExcel.Workbooks(2).Sheets(1).UsedRange.Copy

WITH oExcel.Workbooks(1).Sheets(1)
  loLastCell = .Cells.SpecialCells(xlLastCell)
  mcomo = .Range(m.loLastCell,m.loLastCell).Row
  mcomo = mcomo+1
  .Cells((m.mcomo,1),(m.como,7)).Paste
ENDWITH

I want to select (or directly Paste as above) the row just below the lastcell (m.mcomo+1) and therefore Paste. How may I write the correct Paste instruction (I think it will be simple but I don't know VBA......).Thanks in advance.

Ken White
  • 123,280
  • 14
  • 225
  • 444

1 Answers1

0

Try this, see if it works:

With oExcel.Workbooks(1).Sheets(1)
 Set loLastCell = .Cells.SpecialCells(xlLastCell)
 mcomo = loLastCell.Row
 .Cells(mcomo + 1, 1).PasteSpecial xlPasteAll
End With
  • No! Set loLastCell = .Cells.SpecialCells(xlLastCell) says: Command contains unrecognized phrase/keyword. I defined: #DEFINE xlLastCell 11 and Local loLastCell AS Excel.Range – Claudio Iannone Apr 09 '22 at 19:58
  • What about if you remove the line completely and use 'mcomo = .Cells.SpecialCells(xlLastCell).Row'? Depending on your Excel version xlLastCell might be xlCellTypeLastCell (In Excel 2019 xlLastCell works for me), so try changing the argument as well. – PirateNinja Apr 10 '22 at 07:54