|
-
May 5th, 2003, 02:50 AM
#1
Thread Starter
Don't Panic!
Helpp using Words macros (uugggghhhh)
Hi,
I consider myself an experienced programmer in vba.. unfortunately that is in Access VBA which seems to be a hell of a lot easier than Word or Excel VBA.
Currently I am exporting data into a template built by code and shoved into Word. Initially I tried Words VBA (using record macro) but I was advised to use the proper objects (besides it killed the computer). Any how, I moved to html instead - easier. But it didn't like being transported back into word so I am having to try to do the templates in word objects.
The help file is practically useless as it keeps refering back to the selection object, which is used in the current doc and not via the code :/
I have the following code, which is in a loop.
VB Code:
Set objWTable = Nothing
Set objWTable = objWDoc.Tables.Add(objWRange, 5, 2) 'range,rows,cols
objWTable.Cell(1, 1).Width = objWord.MillimetersToPoints(190) 'row,col (starts at 1)
objWTable.Cell(1, 2).Width = objWord.MillimetersToPoints(10) 'row,col
objWTable.Cell(1, 1).Height = objWord.MillimetersToPoints(20) 'row,col (starts at 1)
objWTable.Cell(1, 2).Height = objWord.MillimetersToPoints(20) 'row,col
objWTable.Cell(2, 1).Width = objWord.MillimetersToPoints(80) 'row,col (starts at 1)
objWTable.Cell(2, 2).Width = objWord.MillimetersToPoints(120) 'row,col
objWTable.Cell(2, 1).Height = objWord.MillimetersToPoints(82) 'row,col (starts at 1)
objWTable.Cell(2, 2).Height = objWord.MillimetersToPoints(82) 'row,col
objWTable.Cell(3, 1).Width = objWord.MillimetersToPoints(80) 'row,col (starts at 1)
objWTable.Cell(3, 2).Width = objWord.MillimetersToPoints(120) 'row,col
objWTable.Cell(3, 1).Height = objWord.MillimetersToPoints(82) 'row,col (starts at 1)
objWTable.Cell(3, 2).Height = objWord.MillimetersToPoints(82) 'row,col
objWTable.Cell(4, 1).Width = objWord.MillimetersToPoints(80) 'row,col (starts at 1)
objWTable.Cell(4, 2).Width = objWord.MillimetersToPoints(120) 'row,col
objWTable.Cell(4, 1).Height = objWord.MillimetersToPoints(82) 'row,col (starts at 1)
objWTable.Cell(4, 2).Height = objWord.MillimetersToPoints(82) 'row,col
objWTable.Cell(5, 1).Width = objWord.MillimetersToPoints(100) 'row,col (starts at 1)
objWTable.Cell(5, 2).Width = objWord.MillimetersToPoints(100) 'row,col
objWTable.Cell(5, 1).Height = objWord.MillimetersToPoints(20) 'row,col (starts at 1)
objWTable.Cell(5, 2).Height = objWord.MillimetersToPoints(20) 'row,col
For lngX = 1 To 5
For lngY = 1 To 2
objWTable.Cell(lngX, lngY).VerticalAlignment = 1 'center
objWTable.Cell(lngX, lngY).Range.ParagraphFormat.Alignment = 1 'wdAlignParagraphCenter
Next
Next
objWTable.Cell(1, 1).Range.ParagraphFormat.Alignment = 0
objWTable.Cell(5, 1).Range.ParagraphFormat.Alignment = 0
objWTable.Cell(5, 2).Range.ParagraphFormat.Alignment = 2
objWTable.Rows.Alignment = 1 'wdAlignRowCenter
This creates my table and reorganises it to the correct widths etc.
First time its called, works fine.
However the second time its called it creates a new table BUT changes the sizes of the first table.
I was under the impression that:
VB Code:
Set objWTable = objWDoc.Tables.Add(objWRange, 5, 2) 'range,rows,cols
Returned a table object, and I thoughtit returned the object just created - is this not the case?
Also I have used the same creation method but for a new table in a cell. This created a table of one row and how ever many columns, even if you specify more than one row. Is this a bug?
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
May 5th, 2003, 08:03 PM
#2
Fanatic Member
I'm not sure what you are trying to do. The problem may be the value you are setting for objWRange. If you run this code in a loop without resetting objWRange, here's what Word is doing:
Word adds a new table. objWTable becomes the new table and objWRange becomes the range of the table. The second time through, objWRange is the range of the first table. Word adds a new table to this range. Because objWRange is a whole table, Word uses the start of objWRange: Cell 1, 1. Word puts a new table in Cell 1, 1. Word is then tries to set the sizes of the new table. You are asking it to expand the table to 200 X 286 inside a cell that is 190 X 20. Obviously that is not possible. So, Word expands Cell 1, 1 as far right and and as far down as it can to accomidate the size of the new table. It makes the new table as close as it can fit within the expandable limits of Cell 1, 1. So the size of Cell 1, 1 in the orignal table is changing because Word is trying to fit a larger object into the cell.
I'm not sure what is going on with your second problem. Word will nest a table with multiple rows in another table.
-
May 6th, 2003, 06:49 AM
#3
Thread Starter
Don't Panic!
VB Code:
Set objWRange = objWDoc.Range(0, 0)
objWRange.MoveEnd wdStory
objWRange.Collapse 0 'wdCollapseEnd
If Not blnPassedOnce Then
blnPassedOnce = True
Else
objWRange.InsertBreak 7 'wdPageBreak
End If
Hi Workhorse, this is the code before which resets the objWRange to the start then the end of the whole document.
I can't seem to put in text data where I want it. What would be the best way to move around in the document? Like I have done above but with characters or words or sentences instead of story ?
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
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
|