Saving a cell name as a word doc

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a list of cells in an excel spreadsheet that I want to use to create
separate word documents from a generic word document.

right now I'm copying the cell name switching to Word opening file Save as
and pasting the name.

It doesn't take long but I've got over a thousand names to save as. Is
there any way in Excel or Word that I can automate this process?
 
Say we have three names in A1 thru C1:

Firstfl
Secondfl
Thirdfl

First put a dummy name in D1. The enter and run this macro:


Sub Macro1()
Dim s As String
Dim i As Integer
For i = 1 To 4
s = Cells(i, 1).Value
fname = "C:\" & s & ".txt"
ActiveWorkbook.SaveAs Filename:= _
fname, FileFormat:= _
xlText, CreateBackup:=False
Next
x = Shell("cmd.exe /c rename C:\*.txt *.doc", 1)
End Sub

The For loop creates a set of .txt files and the Shell command renames them
as .doc. You will have three .doc files as a result.


You can increase from three to any number. The extra dummy entry in needed
to insure the last real entry gets renamed.
 
Thanks it works like a charm.

Gary''s Student said:
Say we have three names in A1 thru C1:

Firstfl
Secondfl
Thirdfl

First put a dummy name in D1. The enter and run this macro:


Sub Macro1()
Dim s As String
Dim i As Integer
For i = 1 To 4
s = Cells(i, 1).Value
fname = "C:\" & s & ".txt"
ActiveWorkbook.SaveAs Filename:= _
fname, FileFormat:= _
xlText, CreateBackup:=False
Next
x = Shell("cmd.exe /c rename C:\*.txt *.doc", 1)
End Sub

The For loop creates a set of .txt files and the Shell command renames them
as .doc. You will have three .doc files as a result.


You can increase from three to any number. The extra dummy entry in needed
to insure the last real entry gets renamed.
 

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

Back
Top