Google Answers Logo
View Question
 
Q: Excel VBA-Create and Save Microsoft Word documents from Text Strings in Excel ( No Answer,   3 Comments )
Question  
Subject: Excel VBA-Create and Save Microsoft Word documents from Text Strings in Excel
Category: Computers > Programming
Asked by: slo2000-ga
List Price: $10.00
Posted: 10 Nov 2006 10:53 PST
Expires: 10 Dec 2006 10:53 PST
Question ID: 781678
My question is a simple one.
I have an Excel spreadsheet with cells of text strings.  I would like
to cycle through the Excel document cells creating and saving a
separate microsoft word document for each text string using VBA.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Excel VBA-Create and Save Microsoft Word documents from Text Strings in Excel
From: naman_patel-ga on 22 Nov 2006 03:39 PST
 
Hi,

Here is the code for ur requirment. u can implement file name logic
what ever required by u. I can do this for selected cells. if u need
for selected cell let me know. solution is in text file.

  Dim fs, f
    Dim fname As String
    Set fs = CreateObject("Scripting.FileSystemObject")
    For x = 0 To 256
        For y = 0 To 65536
            fname = Str(x)
            fname = fname + Str(y) + ".txt"
            Set f = fs.OpenTextFile(fname, ForAppending, TristateFalse)
            f.write Cells(x, y).Text
            f.Close
        Next
    Next
Subject: Re: Excel VBA-Create and Save Microsoft Word documents from Text Strings in Excel
From: slo2000-ga on 26 Nov 2006 16:32 PST
 
This will work if I change extension to .doc? to create microsoft word docs?
Subject: Re: Excel VBA-Create and Save Microsoft Word documents from Text Strings in Excel
From: inventorbob-ga on 28 Nov 2006 09:20 PST
 
1) CREATE a template word document that you want all of them to be
like.  If you want them all blank, just open a blank one and save it
somewhere.  This will be your template file

2) use the following code.  Replace "C:\" with the location you want
to save all of the files.  Note: if your list contains the ".doc"
already, remove the  & ".doc" from the code.  Note2: if your list does
not start in row 1, then change i = 1 to i = <your starting row here>.
 If your list is not in column 1 then change both Cells(i, 1) to
Cells(i, <your column here>)


TemplateFile = Application.GetOpenFilename

Set fs = CreateObject("Scripting.FileSystemObject")

i = 1
Do While Cells(i, 1) <> ""
    fs.CopyFile TemplateFile, "C:\" & Cells(i, 1) & ".doc"
    i = i + 1
Loop

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy