Help with building macro which will creating 6 files out of one.

Z

ZhenyaVirina

Hello,

I need help with creating a macro which will do the following:

I have a single unformatted file which I need to format (each one in
its own way) and then must split up into 6 separate files.

Thank you
 
J

Jean-Guy Marcil

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :
Hello,

I need help with creating a macro which will do the following:

I have a single unformatted file which I need to format (each one in
its own way) and then must split up into 6 separate files.

Are you expecting someone to go off and write the code for you?

First, "need to format (each one in its own way) " is very vague and will be
difficult to do without knowing anything at all.

Write back with specifics and describe what you have trued so far, show us
some of your code too...


--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
G

Greg Maxey

You could also provide some detail.

Lets say you have a unformatted (not sure what that means) document
saved as C:\Base File.doc

You could run a macro something like this:

Sub ScratchMacro()
Dim i As Long
Dim oDoc As Word.Document
For i = 1 To 6
Set oDoc = Documents.Open("C:\Base File.doc")
Select Case i
Case 1
oDoc.Range.Font.Color = wdColorBlue
'Add as much other formatting details as you like.
Case 2
oDoc.Range.Font.Color = wdColorYellow
Case 3
oDoc.Range.Font.Color = wdColorRed
Case 4
oDoc.Range.Font.Color = wdColorGreen
Case 5
oDoc.Range.Font.Color = wdColorIndigo
Case 6
oDoc.Range.Font.Color = wdColorBlueGray
End Select
With oDoc
.SaveAs ("C:\New File" & i & ".doc")
.Close
End With
Next i
Set oDoc = Nothing
End Sub
 
Z

ZhenyaVirina

You could also provide some detail.

Lets say you have a unformatted (not sure what that means) document
saved as C:\Base File.doc

You could run a macro something like this:

Sub ScratchMacro()
Dim i As Long
Dim oDoc As Word.Document
For i = 1 To 6
Set oDoc = Documents.Open("C:\Base File.doc")
Select Case i
Case 1
oDoc.Range.Font.Color = wdColorBlue
'Add as much other formatting details as you like.
Case 2
oDoc.Range.Font.Color = wdColorYellow
Case 3
oDoc.Range.Font.Color = wdColorRed
Case 4
oDoc.Range.Font.Color = wdColorGreen
Case 5
oDoc.Range.Font.Color = wdColorIndigo
Case 6
oDoc.Range.Font.Color = wdColorBlueGray
End Select
With oDoc
.SaveAs ("C:\New File" & i & ".doc")
.Close
End With
Next i
Set oDoc = Nothing
End Sub






- Show quoted text -

For some reason this statement is not recognized by VB " oDoc As
Word.Document ".

I am new to creating micros and it might be a silly questions, sorry
but any help will be appreciated.
 
J

Jean-Guy Marcil

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :
For some reason this statement is not recognized by VB " oDoc As
Word.Document ".

I am new to creating micros and it might be a silly questions, sorry
but any help will be appreciated.

If
Dim oDoc As Word.Document
is throwing an error, then you are not writing this code from the Word VBA
editor.

Are you writing this with Visual Studio or from another application, like
Excel?

I suspect you re trying to control Word form Excel because you posted two
other messages that had to do with Excel. When you post, you have to provide
details, we cannot guess. The more details you will provide the better the
answer and he quicker your problem will be solved.

So, from the Excel (I guess) VBA editor window, do Tools > References >
check the Microsoft Word Object Library xx (xx depends on the version you re
using, normally there is only one so you cannot go wrong).

You have to do this because Excel does not know Word objects and their
properties/methods, you have to tell him you re going to use Word objects.
You do that with a reference.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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