|
-
Feb 27th, 2006, 09:31 AM
#1
Thread Starter
Member
[RESOLVED] macro help
I have a document that looks like this:
%
O0001
( DIAMETER = 4. )
( CORNER RADIUS = .125 )
( STOCK ALLOWANCE = .03 )
G91 G28 Z0
H0 G49
T1
M6
G90
M3 S2500
G5 P1
G61.1
G0 X8.6251 Y-2.1484
G43 Z-1.4 H1 M50
Z-1.9
G1 Z-1.93 F150.
Y8.0004 Z-1.9831
X2.5551 Z-2.0149........say 10 more pages of this.
N200 ( T2 )
( DIAMETER = 1.5 )
( CORNER RADIUS = .125 )
( STOCK ALLOWANCE = .03 )
G91 G28 Z0
H0 G49
T2
M6
G90
M3 S2500
G5 P1
G61.1
X-5.875 Y.1278
G43 Z-1.4 H2 M50
Z-1.9
G1 Z-2.0349.....another 10 pages of this
This repeats many more times. The parenthesis sections are the start of a new toolpath and there could be up to 25 in one document with the document being anywhere from 10-500 pages.
I am looking for help creating a macro that would print the first 20 lines, starting with the parenthesis section, then have a couple blank lines, then the last ten lines before the next section. This would be page 1. Then page two would start with the second parenthesis section and 20 lines, # of blank lines, last ten lines to make up page two. i would like this to go on for as many toolpaths that are on the document.
I would like the output to look like this:
( DIAMETER = 4. )
( CORNER RADIUS = .125 )
( STOCK ALLOWANCE = .03 )
G91 G28 Z0
H0 G49
T1
M6
G90
M3 S2500
G5 P1
G61.1
G0 X8.6251 Y-2.1484
G43 Z-1.4 H1 M50.. up to 20 lines
X8.6251 Y-.1012 (last ten lines of this section)
Y8.0004
X1.375
G3 X.7405 Y6.4686 R.8973
G2 X1.375 Y4.9369 R2.1663
G0 Z-1.4
X-5.875 Y.1278
G5 P0
M01
-----------(page break here)
N200 ( T2 )
( DIAMETER = 1.5 )
( CORNER RADIUS = .125 )
( STOCK ALLOWANCE = .03 )
G91 G28 Z0
H0 G49
T2
M6
G90
M3 S2500
G5 P1
G61.1
X-5.875 Y.1278(up to 20 lines)
X8.6251 Y-.1012(last ten lines)
Y8.0004
X1.375
G3 X.7405 Y6.4686 R.8973
G2 X1.375 Y4.9369 R2.1663
G0 Z-1.4
X-5.875 Y.1278
G5 P0
M01
-----------(page break here)etc.
I have an excel macro that does this but would like it in word and can't get it to work in word. I asked someone else about this and they said the excel macro is totally different so I figured I wouldn't post it. If anyone would like to see it just ask.
If anyone could help, it would be greatly appreciated.
-
Feb 27th, 2006, 09:56 AM
#2
Lively Member
Re: macro help
Out of curiosity, if you just want a printed document, and the excel macro already does it, why do you want it in word? A printout is a printout, right?
-
Feb 27th, 2006, 10:08 AM
#3
Frenzied Member
Re: macro help
wooonelly:
When you say:
"G43 Z-1.4 H1 M50.. up to 20 lines"
Does that mean "there may not be 20 lines before the last 10 lines of the section?
Do you need any indication of the split between the "up to 20 lines" and the last 10 lines?
It would be interesting to know why you have to do this in Word ... do you have some users that do not have Excel installed?
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Feb 27th, 2006, 10:38 AM
#4
Thread Starter
Member
Re: macro help
I have a user who complained because the excel program creates a word document, the way we want it, then he has to open the word doc. and print it. And this is way too much work, I guess. This saves him from going through the document by hand and saves a lot of time but I guess it's not enough time. He wants to open this document in word, push a macro button and have it print the way I described. I didn't write the excel program and am new to this programming but my boss gave this to me to solve.
The up to 20 lines, I mean I want the first twenty lines of each section printed, I just didn't show 20 lines to save space on the post. There is going to be many lines between the parenthesis sections, normally hundreds. And to indicate a split I would like to have a few carriage returns between the first 20 lines and the last 10 lines.
-
Feb 27th, 2006, 11:38 AM
#5
Frenzied Member
Re: macro help
I did most of this with the Macro Recorder ...
Is it GUARANTEED that the "Header" is the ONLY place you will find a "(" character as the first character on the line, and that all "(" characters in the Header will be STRICTLY SEQUENTIAL?
Here is some code that identifies the header (using the above assumption) and then skips down 20 lines:
Code:
Sub Macro2() '< WORD VBA
'Go to the beginning of the document
Selection.HomeKey Unit:=wdStory
'Select the first character on the line
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
'Find the first HEADER section - the first "(" as the first character on the line
While Selection.Text <> "("
'TEST TEST TEST TEST
MsgBox "This is NOT a HEADER Line"
'END TEST
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Wend
'TEST TEST TEST TEST
MsgBox "This is the START of the HEADER Section"
'END TEST
'Skip 20 lines
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=20
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
'TEST TEST TEST TEST
MsgBox "This is the END of the HEADER Section"
'END TEST
End Sub
From here, you'll have to:
* Insert your # blank lines
* Find the start of the NEXT Header section COUNTING LINES AS YOU GO!
* Go back UP 10 lines
* Delete the number of Counted Lines (less 10) above the current line
* Loop again!
Use the Macro Recorder to figure out each individual step, and then insert the polished code snippet into your BM (Big Macro!).
If you have any problems, post the relevant part of your code (or all of it) using "Code Tags", and we'll provide additional assistance.
Last edited by Webtest; Feb 27th, 2006 at 11:58 AM.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Feb 27th, 2006, 04:48 PM
#6
Thread Starter
Member
Re: macro help
The problem with that is that there is not the same number of lines between each section. I can't just tell the macro to go down 505 lines because in the next section it could be 900 lines. I need it to just look for the next "(" and go back ten then keep 30 lines (the ten before and the 20 after the "(")
-
Feb 27th, 2006, 05:01 PM
#7
Frenzied Member
Re: macro help
I realize that the number of lines varies ... that's why I wrote:
* Find the start of the NEXT Header section COUNTING LINES AS YOU GO!
Here is some code (UNTESTED!) you can use to iterate down from the current line to the next Header, counting lines along the way so that you know exactly how many to delete:
Code:
'Line Counter
Dim l_LineCount As Long
'Initialize the line counter
l_LineCount = 0
'NOTE: The cursor must have the first character of a line selected at this point
'Find the NEXT HEADER section - the first "(" as the first character on the line
While Selection.Text <> "("
'TEST TEST TEST TEST
MsgBox "This is NOT a HEADER Line"
'END TEST
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=1
'Advance the Line Counter
l_LineCount = l_LineCount + 1
'Select the first character on the line
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Wend
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|