Select a row, copy and repeat on the next row

J

Jason L

Hi, I posted here earlier, but I think my post was too complicated. Here is
what I am really needing now. A file is downloaded off an AS/400 into an
Excel worksheet (I am new to Excel, so please excuse my bad terminology).
Sometimes there is only one record (which means one row), and sometimes there
are several records (several rows).

Essentially, I need a macro that can select the row, copy it, open a
template I created and paste it into the template (as an xls). It will then
save that file after the data located in a specific field name. The file is
closed then it moves back to the file with the rest of the records. I want
my macro to continue to move down the worksheet until all rows have been
copied and pasted into new worksheets.

'This selected the specific data that was later used as a file name'

Selection.Find.Execute Replace:=wdReplaceAll
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=18,
Extend:=wdExtend

'This code declared the selected data above as fname. It then saved the
file with that data and moved onto the next record in the file.'

fname = Selection

Dim i As Integer, Source As Document, Target As Document
Set Source = ActiveDocument
For i = 1 To Source.Paragraphs.Count
Set Target = Documents.Add
Target.Range = Source.Paragraphs(i).Range
Target.SaveAs Filename: = fname & ".doc"
Target.Close
Set Target = Nothing
Next i
Set Source = Nothing

Thanks very much for any assistance you can provide.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top