Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Sep 21, 2019 3:46 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: WORD: How to use WordApplication
PostPosted: Sat Sep 25, 2010 3:19 am 
Offline
User avatar

Joined: Wed Nov 15, 2006 3:50 pm
Posts: 2353
Location: England
In a Word Macro, I have recorded these lines

//move down by a line

Selection.MoveDown Unit:=wdLine, Count:=1

Like most other recorded lines, the original code refers to selection over and over again.
Yet the WordObject seems to have no concept of this.
How do you translate selection. into commands that work with a Word Doc object?

Has anyone any example code to show how to (for example)

Type hello
insert a picture
Move to the end of the document
Insert a table
fill the table?


Top
 Profile  
Reply with quote  
 Post subject: Re: WORD: How to use WordApplication
PostPosted: Sun Sep 26, 2010 5:03 am 
Offline
User avatar

Joined: Wed Nov 15, 2006 3:50 pm
Posts: 2353
Location: England
Nobody uses the WordApplication class at all?

(Which would seem to be the case after 3 days of searching the internet.. The only examples I can find are 'open word, stick some text in, and close word')


Top
 Profile  
Reply with quote  
 Post subject: Re: WORD: How to use WordApplication
PostPosted: Sun Sep 26, 2010 4:01 pm 
Offline

Joined: Fri Sep 30, 2005 9:29 am
Posts: 732
Location: California
dim wrdApplication As WordApplication
dim docDocument As WordDocument
dim rowInvoiceRow As WordRow
dim tblWordTable As WordTable
dim intRowCounter As Integer
dim intColumnCounter As Integer

wrdApplication = new WordApplication
wrdApplication.Visible = True

docDocument = wrdApplication.Documents.Add()

'Request #1: type hello
wrdApplication.Selection.TypeText "Hello"
'put some paragraphs after the text
wrdApplication.Selection.InsertParagraph
wrdApplication.Selection.InsertParagraph
wrdApplication.Selection.InsertParagraph

'move back to the start of the document so there's some indication of movement
wrdApplication.Selection.GoTo_(Office.wdGoToLine, Office.wdGoToAbsolute, office.wdGoToFirst)

'adding some paragraphs after the picture so there's some movement when moving to the end of the document
wrdApplication.Selection.InsertParagraph
wrdApplication.Selection.InsertParagraph

'Request #2: insert a picture
wrdApplication.Selection.InlineShapes.AddPicture("C:\Program Files\Microsoft Office\MEDIA\CAGCAT10\j0217698.wmf", false, true)

'Request #3: Move to the end of the document
wrdApplication.Selection.GoTo_(Office.wdGoToLine, Office.wdGoToLast)

'Request #4: Insert a table
tblWordTable = docDocument.Tables.Add(wrdApplication.Selection.Range, 5, 2)

'Request #5: fill the table
for intRowCounter = 1 to 5
for intColumnCounter = 1 to 2
tblWordTable.Cell(intRowCounter, intColumnCounter).Range.Select_
wrdApplication.Selection.TypeText "Row: " + str( intRowCounter) + ", Column: " + str(intColumnCounter)
Next
Next


Top
 Profile  
Reply with quote  
 Post subject: Re: WORD: How to use WordApplication
PostPosted: Sun Sep 26, 2010 5:14 pm 
Offline
User avatar

Joined: Wed Nov 15, 2006 3:50 pm
Posts: 2353
Location: England
dglass: immense thanks.
It will be a day or two before I get to play with this now (my weekend has ended), but there is a lot there that is going to be very useful.

_________________
Still RB2009 R5.1
Mac 10.6 + Windows 7/XP + Ubuntu Linux in Vmware
on a Macbook 2.16


Top
 Profile  
Reply with quote  
 Post subject: Re: WORD: How to use WordApplication
PostPosted: Fri Sep 02, 2011 12:59 pm 
Offline

Joined: Wed Apr 27, 2011 12:33 pm
Posts: 13
I'm going to resurrect this thread in hopes that jeff or dglass might still get an email notification...

I've been looking for some help with this issue for a while and it seems that the RS documentation refers people to VB for a lot of Word automation, which is of no help to me because I don't do VB so I'm not adept at translating VB > RS.

I think this may solve the issue that I have (written about here)- does anyone know how to use a Find to set the pointer for WordApplication.Selection so that if I were to do WordApplication.Selection.TypeText - I can control where it types beyond using wrdApplication.Selection.GoTo_(Office.wdGoToLine, Office.wdGoToAbsolute, office.wdGoToFirst)?

My real problem is not being able to send EOL in a Find/Replace. I'm trying to use the Find/Replace in conjunction with InsertParagraph or something along those lines.

Any help is much appreciated. Thanks.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group