PC Review


Reply
Thread Tools Rate Thread

Change paragraph format in Word from Excel...

 
 
gab1972
Guest
Posts: n/a
 
      6th Oct 2009
Okay, so yesterday I figured out how to find and replace some
information in a Word document from Excel. The information I find and
replace in Word from Excel has multiple lines - so when I'm done I
have several lines of information. I need to format this into a
numbered list. Anyone know how to change the paragraph formatting in
Word from Excel? The line of code I have doesn't seem to work so I'm
thinking I either didn't do it right or I'm missing something or I
have it in the wrong section.

Thanks in advance!

Sub EditWordDoc()
Dim wrdApp As Word.Application 'creates a dialog with Word
Dim wrdDoc As Word.Document 'creates a dialog with a document
Set wrdApp = GetObject(, "Word.Application")
wrdApp.Visible = True 'show the document
wrdApp.Activate
Set wrdDoc = wrdApp.Documents.Open("Z:\COMMON FILES\Encroachment
Permits\Permit.Tracker\Testing\testdoc.doc")
With wrdDoc.Range.Find 'Find within the document...
.Text = "aaaa" '...this text and then replace it
with...
.Replacement.Text = "Insufficient plans." & vbCr & "Other
stuff." & vbCr '...this text
.Execute Replace:=wdReplaceAll 'replace all
'.Execute Format:=wdStyleListNumber <--- this doesn't
work
End With

'clear everything and quit
'wrdApp.Quit ' close the Word application
'Set wrdDoc = Nothing
'Set wrdApp = Nothing
End Sub
 
Reply With Quote
 
 
 
 
gab1972
Guest
Posts: n/a
 
      6th Oct 2009
On Oct 6, 8:37*am, gab1972 <glen.braml...@gmail.com> wrote:
> Okay, so yesterday I figured out how to find and replace some
> information in a Word document from Excel. *The information I find and
> replace in Word from Excel has multiple lines - so when I'm done I
> have several lines of information. *I need to format this into a
> numbered list. *Anyone know how to change the paragraph formatting in
> Word from Excel? *The line of code I have doesn't seem to work so I'm
> thinking I either didn't do it right or I'm missing something or I
> have it in the wrong section.
>
> Thanks in advance!
>
> Sub EditWordDoc()
> Dim wrdApp As Word.Application *'creates a dialog with Word
> Dim wrdDoc As Word.Document * * 'creates a dialog with a document
> * * Set wrdApp = GetObject(, "Word.Application")
> * * wrdApp.Visible = True * 'show the document
> * * wrdApp.Activate
> * * Set wrdDoc = wrdApp.Documents.Open("Z:\COMMON FILES\Encroachment
> Permits\Permit.Tracker\Testing\testdoc.doc")
> * * * * With wrdDoc.Range.Find *'Find within the document...
> * * * * * * .Text = "aaaa" * * *'...this text and then replace it
> with...
> * * * * * * .Replacement.Text = "Insufficient plans." & vbCr & "Other
> stuff." & vbCr * *'...this text
> * * * * * * .Execute Replace:=wdReplaceAll *'replace all
> * * * * * * '.Execute Format:=wdStyleListNumber *<--- this doesn't
> work
> * * * * End With
>
> * * 'clear everything and quit
> * * 'wrdApp.Quit ' close the Word application
> * * 'Set wrdDoc = Nothing
> * * 'Set wrdApp = Nothing
> End Sub


Ugh...I did it again. I found the answer to my own question. It
never fails...I try try try to figure out what I'm doing wrong, then
post here, and then less than 10-15 minutes later I find the answer to
my own question.

Anyways, like always, I try to share what I found even if I answered
my own question. So what I have so far is coding that , from Excel, I
can find and replace text and then number format it. I found a line
of coding that goes with my wdStyleListNumber ( .Replacement.Style =
'whatever style you want) In this case, I wanted a numbered list so I
used my wdStyleListNumber. The next problem I ran into was that it
was far left justifying it and I needed it indented a few tabs over.
So I found there are multiple wdStyleListNumber's ranging from 1 to
5. In my case, 3 worked perfect. So here's a snippet of my edited
coding for your reading pleasure...maybe it'll help someone else out.

With wrdDoc.Range.Find 'Find within the document...
.Text = "aaaa" '...this text and then replace it
with...
.Replacement.Text = "Insufficient plans." '& vbCr & "Other
stuff." & vbCr '...this text
.Replacement.Style = wdStyleListNumber3 '<--- this
numbers the list and then moves it over 2 tabs justified
.Execute Replace:=wdReplaceAll 'replace all

End With

Along this same lines, you can also bullet your list and pretty much
completely change the whole formatting. Here is where I found my list
of wdStyle's:

http://techsupt.winbatch.com/webcgi/...~Constants.txt

Hope this helps someone else!
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
word to excel format change rumkus@hotmail.com Microsoft Excel Programming 2 3rd May 2009 11:51 AM
When I format a paragraph, why is it a global change? John Microsoft Word Document Management 2 13th Aug 2008 09:27 PM
format excel text column to word paragraph =?Utf-8?B?c2llcnJhbGlnaHRmb290?= Microsoft Word Document Management 2 3rd Mar 2007 10:58 PM
Importing Word Paragraph to Excel - 1 cell, same formating -- I lose the format Chris DeNardis Microsoft Excel Programming 4 23rd Feb 2005 04:07 PM
How do I take a word table and change it into a paragraph format? =?Utf-8?B?R2xvcmlh?= Microsoft Word Document Management 1 8th Nov 2004 07:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:40 AM.