Inserting field value into table

B

Bonsai Bill

I have what is hopefully a simple question. I figured out the VBA code to
generate a two column, 1 row table so that I can enter an equation number in
right column. What is the code to insert the equation number into the right
column cell? (I am using chapter number with the equation number.) I will be
cross referencing the equation number.

I am using Word XP and WinXP but will need to use it in Office 2007 soon
with Vista or WinXP.

Thanks in advance for the help!
 
M

macropod

Hi Bonsai Bill,

You'd usually spcify the cell you want to use. For example, the following macro creates a table of whatever row/col count you choose
(up to 127 & 63, respectively - 63 is Word's column limit) then loops through each cell inserting its address. The cell references
are in the form of .Cell(Row,Col).Range.Text = "string".

Sub Demo()
Dim Cols As Integer
Dim Rows As Integer
Dim i As Integer
Dim j As Integer
Cols = CInt(InputBox("# of Columns"))
If Cols > 63 Then Cols = 63
Rows = CInt(InputBox("# of Rows"))
If Rows > 127 Then Rows = 127
With Selection
.Tables.Add .Range, Rows, Cols
With .Tables(1)
For i = 1 To Cols
For j = 1 To Rows
If i > 26 Then
.Cell(j, i).Range.Text = "Cell Address: " & Chr(64 + Int(i / 26)) & _
Chr(64 + (i Mod 26)) & j
Else
.Cell(j, i).Range.Text = "Cell Address: " & Chr(64 + i) & j
End If
Next
Next
End With
End With
End Sub
 
B

Bonsai Bill

Thanks for your reply macropod. I stumbled around and finally got what I
needed using autotext for the caption insertion. I am saving your macro
because I will probably use it before long.

I do have one more question: After inserting the caption in the table I need
the cursor to go to the next line below. Otherwise user will hit return while
still in table. How can I make the selection jump to beginning of the line
below the table?

Again, thanks for your help!


macropod said:
Hi Bonsai Bill,

You'd usually spcify the cell you want to use. For example, the following macro creates a table of whatever row/col count you choose
(up to 127 & 63, respectively - 63 is Word's column limit) then loops through each cell inserting its address. The cell references
are in the form of .Cell(Row,Col).Range.Text = "string".

Sub Demo()
Dim Cols As Integer
Dim Rows As Integer
Dim i As Integer
Dim j As Integer
Cols = CInt(InputBox("# of Columns"))
If Cols > 63 Then Cols = 63
Rows = CInt(InputBox("# of Rows"))
If Rows > 127 Then Rows = 127
With Selection
.Tables.Add .Range, Rows, Cols
With .Tables(1)
For i = 1 To Cols
For j = 1 To Rows
If i > 26 Then
.Cell(j, i).Range.Text = "Cell Address: " & Chr(64 + Int(i / 26)) & _
Chr(64 + (i Mod 26)) & j
Else
.Cell(j, i).Range.Text = "Cell Address: " & Chr(64 + i) & j
End If
Next
Next
End With
End With
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


Bonsai Bill said:
I have what is hopefully a simple question. I figured out the VBA code to
generate a two column, 1 row table so that I can enter an equation number in
right column. What is the code to insert the equation number into the right
column cell? (I am using chapter number with the equation number.) I will be
cross referencing the equation number.

I am using Word XP and WinXP but will need to use it in Office 2007 soon
with Vista or WinXP.

Thanks in advance for the help!
 
A

alborg

Hi Bill:

What should work are the following, try-

Selection.GoTo What:=wdGoToLine, Which:=wdGoToNext, Count:=1

If that goes to the next line in the cell, then try-

Selection.GoTo What:=wdGoToBookmark, Name:="LineAfterTableBookmark"

Cheers,
Al

Bonsai Bill said:
Thanks for your reply macropod. I stumbled around and finally got what I
needed using autotext for the caption insertion. I am saving your macro
because I will probably use it before long.

I do have one more question: After inserting the caption in the table I need
the cursor to go to the next line below. Otherwise user will hit return while
still in table. How can I make the selection jump to beginning of the line
below the table?

Again, thanks for your help!


macropod said:
Hi Bonsai Bill,

You'd usually spcify the cell you want to use. For example, the following macro creates a table of whatever row/col count you choose
(up to 127 & 63, respectively - 63 is Word's column limit) then loops through each cell inserting its address. The cell references
are in the form of .Cell(Row,Col).Range.Text = "string".

Sub Demo()
Dim Cols As Integer
Dim Rows As Integer
Dim i As Integer
Dim j As Integer
Cols = CInt(InputBox("# of Columns"))
If Cols > 63 Then Cols = 63
Rows = CInt(InputBox("# of Rows"))
If Rows > 127 Then Rows = 127
With Selection
.Tables.Add .Range, Rows, Cols
With .Tables(1)
For i = 1 To Cols
For j = 1 To Rows
If i > 26 Then
.Cell(j, i).Range.Text = "Cell Address: " & Chr(64 + Int(i / 26)) & _
Chr(64 + (i Mod 26)) & j
Else
.Cell(j, i).Range.Text = "Cell Address: " & Chr(64 + i) & j
End If
Next
Next
End With
End With
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


Bonsai Bill said:
I have what is hopefully a simple question. I figured out the VBA code to
generate a two column, 1 row table so that I can enter an equation number in
right column. What is the code to insert the equation number into the right
column cell? (I am using chapter number with the equation number.) I will be
cross referencing the equation number.

I am using Word XP and WinXP but will need to use it in Office 2007 soon
with Vista or WinXP.

Thanks in advance for the help!
 
B

Bonsai Bill

Hi Al,

Thanks for your suggestions. Because the selection was in last cell of table
the wdGoToLine work great.

I had thought about adding a bookmark before generating the table but had
hoped there was an easier way. I think I prefer selecting the last cell of
table first and then using wdGoToLine better.

Thanks for your help!

alborg said:
Hi Bill:

What should work are the following, try-

Selection.GoTo What:=wdGoToLine, Which:=wdGoToNext, Count:=1

If that goes to the next line in the cell, then try-

Selection.GoTo What:=wdGoToBookmark, Name:="LineAfterTableBookmark"

Cheers,
Al

Bonsai Bill said:
Thanks for your reply macropod. I stumbled around and finally got what I
needed using autotext for the caption insertion. I am saving your macro
because I will probably use it before long.

I do have one more question: After inserting the caption in the table I need
the cursor to go to the next line below. Otherwise user will hit return while
still in table. How can I make the selection jump to beginning of the line
below the table?

Again, thanks for your help!


macropod said:
Hi Bonsai Bill,

You'd usually spcify the cell you want to use. For example, the following macro creates a table of whatever row/col count you choose
(up to 127 & 63, respectively - 63 is Word's column limit) then loops through each cell inserting its address. The cell references
are in the form of .Cell(Row,Col).Range.Text = "string".

Sub Demo()
Dim Cols As Integer
Dim Rows As Integer
Dim i As Integer
Dim j As Integer
Cols = CInt(InputBox("# of Columns"))
If Cols > 63 Then Cols = 63
Rows = CInt(InputBox("# of Rows"))
If Rows > 127 Then Rows = 127
With Selection
.Tables.Add .Range, Rows, Cols
With .Tables(1)
For i = 1 To Cols
For j = 1 To Rows
If i > 26 Then
.Cell(j, i).Range.Text = "Cell Address: " & Chr(64 + Int(i / 26)) & _
Chr(64 + (i Mod 26)) & j
Else
.Cell(j, i).Range.Text = "Cell Address: " & Chr(64 + i) & j
End If
Next
Next
End With
End With
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


I have what is hopefully a simple question. I figured out the VBA code to
generate a two column, 1 row table so that I can enter an equation number in
right column. What is the code to insert the equation number into the right
column cell? (I am using chapter number with the equation number.) I will be
cross referencing the equation number.

I am using Word XP and WinXP but will need to use it in Office 2007 soon
with Vista or WinXP.

Thanks in advance for the help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top