View Single Post
  #7   Report Post  
Posted to microsoft.public.word.tables
Jack Jack is offline
external usenet poster
 
Posts: 9
Default Losing textbox on table

Thanks for responding. Let me be more specific what I am trying to do
I am basically making a 13 month calendar. In the document there is 13
pages each page contains a table( a little smaller than the size of the
page) for the main month. I have code that generates the days of the month
for each page and that all works correctly.

Now what I need is to create for each main month two small submonths that
represent the previous and next months like you see in many calendars.
These two "small months" will be placed in one of the cells of the month.

The way I do it is that I have created a shape which is just a text box that
is sized to fit in one of the cells of the "big month"(table on a page).
Within this small textbox I have a table whose cells contains the days of
the month. I have code that fills the table within the textbox with days of
the month for any given month and year.

So after I create a given main month, I use the single textbox, fill with
the previous month's data, copy it and paste it into the main month table.
I then generate another for the Next month and past it into the big month.

I repeat this process for all the months of the calendar.
I hope this clarifies whatI am trying to do. I have inclued the code from
the main routine. Wehn i=1, ti goes through the whole process correctly and
pstes the two submonths onto the table(although not in the correct
position)(which I can easily just move them later). The error occurs when
i=2 .when it tries to paste the first of the submonths. the error is 4198

thanks for any help.
Jack


Here is the code for the main routine
Public Sub MainControl()
Dim iYear, iMonth, iCalendarYear, iSubMonth As Integer
Dim dt As Date
Dim shp As Shape
Dim tbl As Table
Dim rng As Range
iCalendarYear = 2006 'This would normaly come from an input
For i = 1 To 13 'will be 1 to 13
If i = 13 Then
iMonth = 1
iYear = iCalendarYear + 1
Else
iMonth = i
iYear = iCalendarYear
End If
dt = DateSerial(iYear, iMonth, 1)

'Create month calendar
Set tbl = ActiveDocument.Tables(i)
Set rng = tbl.Range.Cells(8).Range
Call CreateMonth(dt, tbl)
'Create subCalendars
Set shp = ActiveDocument.Shapes("submonth")
Set tbl = shp.TextFrame.TextRange.Tables(1)
'Create Previous month
If iMonth - 1 0 Then
dt = DateSerial(iYear - 1, 12, 1)
Else
dt = DateSerial(iYear, iMonth - 1, 1)
End If
Call CreateSubMonths(dt, tbl)
'Paste shape into calendar table rnage
shp.Select
Selection.Copy
rng.Paste

'Create next month
Set shp = ActiveDocument.Shapes("submonth")
Set tbl = shp.TextFrame.TextRange.Tables(1)
If iMonth + 1 12 Then
dt = DateSerial(iYear + 1, 1, 1)
Else
dt = DateSerial(iYear, iMonth + 1, 1)
End If
Call CreateSubMonths(dt, tbl)
shp.Select
Selection.Copy
rng.Paste
Next i
End Sub

"macropod" wrote in message
...
Hi Jack,

I'm not quite sure what you're trying to do here, but it looks as though
you're trying to capture the user's input into a text box and transfer
that
to particular table cells. The code you posted, though, seems to simply
create additional text boxes instead.

If you're trying to capture the user's input and transfer that to
particular
table cells, try something like the following:

Sub Table_Input()
Dim i As Integer
Dim str As String
For i = 1 To ActiveDocument.Tables.Count
With ActiveDocument.Tables(i).Cell(2, 2)
str = Left(.Range.Text, Len(.Range.Text) - 2)
.Range.Delete
.Range.Text = InputBox("Text to input in table " & i, , str)
End With
Next i
End Sub

The above code cycles through all tables in the document, clearing the
contents of cell B2 and soliciting a new text string with the original
text
as the default. The user can then clear, edit/replace or add to the former
string. If you need to have the last table's update reflected in a text
box,
the code for that could be added to the macro.

An even simpler way to update the tables would be to insert text
formfields
into the appropriate cells, and protect the document for forms. The
document
wouldn't automatically solicit input for each formfield, though that could
be driven from code, but the user wouldn't be restricted to updating a few
cells by running a macro that cycles though all tables.

If this isn't helpful, on which line of code were you getting the error
4198? Some more of your code for context would help too.

Cheers
PS: Typo in your posted code - 'tbl' is defined 'set
tbl=activedocument.tables(i)', but 'tlb' is used 'set
rng=tlb.range.cells(2).range'.

--
macropod
[MVP - Microsoft Word]


"Jack" wrote in message
. ..
I see you have the mvp credentials. I have another question that relates

to
my previous one that yu may have some insight. I have several(like 13)
tables and a separte textbox that is rectangular which is located on the
last page of the document.. What i want to do is change the text in the
box, copy that textbox and paste a copy in one of the table cells using

VBA
code. I would repeat this for each of the tables.
That would help solve my manual placing it there. The reason for doing
it
in code I have a number of these to place

I have tried code like:

set tbl=activedocument.tables(i)
set shp=activedocument.shapes("TemplateBox")
'Change text in box
shp.textframe.textrange.text="bbbbbb"or whatever
shp.select
selection.copy
set rng=tlb.range.cells(2).range
rng.paste


that works on the first table(although it in not quite in the proper
cell..but I can move it around). But when I do it on a subsequent table,

I
get an error 4198
If you can guide me on this, I wont worry about my orginal question
Thanks
Jack


"macropod" wrote in message
...
Hi Jack,

It could still be a display driver problem. Have you checked for later
'release' drivers (i.e. not betas) for your video card?

Also, try going into the control panel and reducing the amount of

hardware
acceleration.

Cheers

--
macropod
[MVP - Microsoft Word]


"Jack" wrote in message
. ..
I tried that and it didnt make any difference
Jack
"macropod" wrote in message
...
Hi Jack,

Could be a display driver problem. Have you tried scrolling up/down

to
an
area that doesn't show either the table or text box, then back
again,
after
moving the text box? Does that have any effect?

Cheers

--
macropod
[MVP - Microsoft Word]


"Jack" wrote in message
. ..
I have a text box on a page that has a table. The text box is
above
the
table. When I drag the text box to place into a cell in the table,

it
disappears. The strange thing is that when I drag it so part is
off
the
table and some is on it, all of the text box displays ok. However,
dragging
further in it disappears.
I am not sure what is happening. I have other text boxes that can

be
dragged into other cells and they work ok. I have the layout set
to
"In
front of text"
Jack