ABXZone Computer  Forums



Welcome to the ABXZone Computer Forums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Reply
 
LinkBack Thread Tools Display Modes
Old 08-13-2008, 11:28 AM   #1
Registered User
 
Join Date: Aug 2008
Posts: 3
OpenOffice/MS Word question

Hi, got what could be a weird question here-

First of all, I'm not really a newbie here, my old account doesn't seem to exist anymore and I no longer have my old email :\

Anyway, was wondering if anyone would have some idea if I could do the following in Word or OpenOffice.

I have a text document, maybe a couple hundred lines long. On each line is maybe 10 items of text.

example-

blaaaaaah
wjwjjdjd
asdsdiusdjsj
sjcjcjsjasj
sjdjdjsja

Now, if I had a document with all that text already, would there be some way I could universally do something to each line of text? Specifically, in this case, I want to put each line in quotations and put a semicolon at the end.

example-

"blaaaaah";
"wjwjjdjd";
"sdsdiusdjsj";
"sjcjcjsjasj";
"sjdjdjsja";

And that's pretty much it. Hope someone here can help me
(Offline)   Reply With Quote

Advertisement [Remove Advertisement]

Old 08-13-2008, 12:46 PM   #2
Premium Member
 
Join Date: May 2005
Location: Orlando Area Florida
Posts: 120
Re: OpenOffice/MS Word question

For MS Word, you would simply record a macro of manually editing one line of the text, then going to the next line. Since the line-length varies, you need to use "home" and "end" to get to the beginning and end of the line. Then, depending on your skills, the size of the document, etc, you could edit the macro to cover the whole document, or assign a keystroke.

For Example:


Go to "Tools"->"Macro"->"Record New Macro"

When the dialog box pops up, pick the keyboard button, assign a [Ctrl][Q] to the macro, and press "Close".

Press [Home] to get to the beginning of the line.
Type ["]
Press [End]
Type ["]
Type [;]
Press [Home]
Press [Down Arrow]

Click on the square "Stop" Button of the little dialog box that popped up when you started recording.

Press [Ctrl][Q] until the entire document has been edited. Be careful near the end, or you'll have to edit the last line.

(Or, you could edit the Visual Basic file to look for the end of the document. But, that requires some programming knowledge.)

I don't THINK that OpenOffice uses the same VBA macro language or record methods. But, OpenOffice should have something equivalent.
(Offline)   Reply With Quote
Old 08-13-2008, 02:40 PM   #3
Registered User
 
Join Date: Aug 2008
Posts: 3
Re: OpenOffice/MS Word question

Terry-

That worked beautifully. I really appreciate it. Now the next step I think is how to get it to do it automatically till it hits the end of the document. I'm using OpenOffice, and the recording of a macro seems like it's pretty much the same as MS Word.

Now, I really don't have any programming experience, but the language that OpenOffice does kinda look like VB (as far as I know anyway) and it calls it OpenOffice.Org Basic...so either VB or at least very similar?

Anyway, this is a cut n paste of what I get when I go into the macro editor for this particular macro-

REM ***** BASIC *****

Sub Main

End Sub


sub SODICK
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToStartOfLine", "", 0, Array())

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Text"
args2(0).Value = CHR$(34)

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args2())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToEndOfLine", "", 0, Array())

rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Text"
args4(0).Value = ";"+CHR$(34)

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args4())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToStartOfLine", "", 0, Array())

rem ----------------------------------------------------------------------
dim args6(1) as new com.sun.star.beans.PropertyValue
args6(0).Name = "Count"
args6(0).Value = 1
args6(1).Name = "Select"
args6(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args6())


end sub



What I need this macro to do is repeat itself until it reaches the end of the document. I don't know if you, Terry, have any programming knowledge, or if someone else could help me out, but any help is really appreciated.
(Offline)   Reply With Quote
Old 08-14-2008, 02:04 PM   #4
Premium Member
 
Join Date: May 2005
Location: Orlando Area Florida
Posts: 120
Re: OpenOffice/MS Word question

The following code compares the Start Property of the two bookmarks, and it works in MSWord. From the looks of YOUR code, the two marco languages are different, though.

Sub Macro6()
'
' Macro6 Macro
' Macro recorded 8/14/2008 by Terry Reynolds
'
Selection.HomeKey Unit:=wdStory
Do Until ActiveDocument.Bookmarks("\Sel").Start = ActiveDocument.Bookmarks("\EndOfDoc").Start
Selection.HomeKey Unit:=wdLine
Selection.TypeText Text:=""""
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=""";"
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.EndKey Unit:=wdLine
Loop
End Sub


I found another sample code (shown below, edited for clarity) at more than one location, but it won't work. It compares the default property of the "\Sel" bookmark to that of the "\EndOfDoc" bookmark. The default property of a bookmark is its name, so "\Sel" = "\EndOfDoc" is always false. If you use it, the program won't stop running until Word crashes.

Loop: Do Until End of Document
Do Until ActiveDocument.Bookmarks("\Sel") = ActiveDocument.Bookmarks("\EndOfDoc")
(INSERT RECORDED MACRO HERE)
Loop

BTW, I'm a good C programmer, but my knowledge of Visual Basic is just enough to muddle through (with a book and trial-and-error) to accomplish specific tasks I may require. Perhaps, one of these days I'll roll up my sleeves and make a real effort to learn the language properly (and to think object-oriented instead of procedural).

Let me know how things turn out. I'm interested.

Last edited by Terry Reynolds; 08-15-2008 at 07:38 AM..
(Offline)   Reply With Quote
Reply


Thread Tools
Display Modes

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 On




Powered by vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.1
vBulletin Skin developed by: vBStyles.com

© 2006 - 2009 ABXZone Forums | About ABX Zone Forums | Advertising Opportunities | Legal | A member of the Crowdgather Forum Community