A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How to get the current Table Index value in my VBA Macro?



 
 
Thread Tools Display Modes
  #1  
Old February 27th, 2008, 10:29 PM posted to microsoft.public.word.tables
vrk1
external usenet poster
 
Posts: 12
Default How to get the current Table Index value in my VBA Macro?

Hi,

I have a macro that splits the cells that have Hard returns inside all the
tables in my current document into separate rows. Someone sent me this macro
below to perform this function.

If I need this macro to operate only on the current Cell where my cursor is
and not all the tables in my document, how should I modify this?


Macro Below:

Sub RowSplit()

For x = 1 To ThisDocument.Tables.Count

For Each r In ThisDocument.Tables(x).Rows

If InStr(1, r, Chr(13)) Len(r.Cells(1).Range) Then

rowsArray = Split(r.Cells(1).Range, Chr(13))
nSubRowCount = UBound(rowsArray)

If nSubRowCount 1 Then
r.Select

For i = nSubRowCount To 1 Step -1
If Len(Replace(rowsArray(i), Chr(7), "")) 0 Then
Selection.InsertRowsBelow
ThisDocument.Tables(x).Cell(r.Index + 1,
1).Range = rowsArray(i)
r.Select
End If
Next
Selection.Range = rowsArray(0)
End If

End If

Next
Next

End Sub

  #2  
Old February 28th, 2008, 01:06 AM posted to microsoft.public.word.tables
Peter A
external usenet poster
 
Posts: 325
Default How to get the current Table Index value in my VBA Macro?

In article , vrk1
@discussions.microsoft.com says...
Hi,

I have a macro that splits the cells that have Hard returns inside all the
tables in my current document into separate rows. Someone sent me this macro
below to perform this function.

If I need this macro to operate only on the current Cell where my cursor is
and not all the tables in my document, how should I modify this?


snipped

You should ask this question on one of the VBA groups.


--
Peter Aitken
Author, MS Word for Medical and Technical Writers
www.tech-word.com
  #3  
Old February 28th, 2008, 09:32 AM posted to microsoft.public.word.tables
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default How to get the current Table Index value in my VBA Macro?

Replace

For x = 1 To ThisDocument.Tables.Count

For Each r In ThisDocument.Tables(x).Rows

With

For Each r In Selection.Tables(1).Rows

and delete the final Next

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"vrk1" wrote in message
...
Hi,

I have a macro that splits the cells that have Hard returns inside all the
tables in my current document into separate rows. Someone sent me this
macro
below to perform this function.

If I need this macro to operate only on the current Cell where my cursor
is
and not all the tables in my document, how should I modify this?


Macro Below:

Sub RowSplit()

For x = 1 To ThisDocument.Tables.Count

For Each r In ThisDocument.Tables(x).Rows

If InStr(1, r, Chr(13)) Len(r.Cells(1).Range) Then

rowsArray = Split(r.Cells(1).Range, Chr(13))
nSubRowCount = UBound(rowsArray)

If nSubRowCount 1 Then
r.Select

For i = nSubRowCount To 1 Step -1
If Len(Replace(rowsArray(i), Chr(7), "")) 0
Then
Selection.InsertRowsBelow
ThisDocument.Tables(x).Cell(r.Index + 1,
1).Range = rowsArray(i)
r.Select
End If
Next
Selection.Range = rowsArray(0)
End If

End If

Next
Next

End Sub



  #4  
Old February 28th, 2008, 03:32 PM posted to microsoft.public.word.tables
vrk1
external usenet poster
 
Posts: 12
Default How to get the current Table Index value in my VBA Macro?

My apologies. I will try to move this to the Word programming area, if I can.

Just to follow through on your response, when I tried what you suggested I
get an error message:

"The requested member of the collection does not exist."

Any ideas? Thank you.


"Doug Robbins - Word MVP" wrote:

Replace

For x = 1 To ThisDocument.Tables.Count

For Each r In ThisDocument.Tables(x).Rows

With

For Each r In Selection.Tables(1).Rows

and delete the final Next

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"vrk1" wrote in message
...
Hi,

I have a macro that splits the cells that have Hard returns inside all the
tables in my current document into separate rows. Someone sent me this
macro
below to perform this function.

If I need this macro to operate only on the current Cell where my cursor
is
and not all the tables in my document, how should I modify this?


Macro Below:

Sub RowSplit()

For x = 1 To ThisDocument.Tables.Count

For Each r In ThisDocument.Tables(x).Rows

If InStr(1, r, Chr(13)) Len(r.Cells(1).Range) Then

rowsArray = Split(r.Cells(1).Range, Chr(13))
nSubRowCount = UBound(rowsArray)

If nSubRowCount 1 Then
r.Select

For i = nSubRowCount To 1 Step -1
If Len(Replace(rowsArray(i), Chr(7), "")) 0
Then
Selection.InsertRowsBelow
ThisDocument.Tables(x).Cell(r.Index + 1,
1).Range = rowsArray(i)
r.Select
End If
Next
Selection.Range = rowsArray(0)
End If

End If

Next
Next

End Sub




  #5  
Old February 28th, 2008, 07:34 PM posted to microsoft.public.word.tables
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default How to get the current Table Index value in my VBA Macro?

You probably did not have the selection in a table when you ran it.

Enclose the routine in

If Selection.Information(wdWithInTable) = True Then
'code for routine here
End If

so that the code will only run if the selection is in a table.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"vrk1" wrote in message
...
My apologies. I will try to move this to the Word programming area, if I
can.

Just to follow through on your response, when I tried what you suggested I
get an error message:

"The requested member of the collection does not exist."

Any ideas? Thank you.


"Doug Robbins - Word MVP" wrote:

Replace

For x = 1 To ThisDocument.Tables.Count

For Each r In ThisDocument.Tables(x).Rows

With

For Each r In Selection.Tables(1).Rows

and delete the final Next

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"vrk1" wrote in message
...
Hi,

I have a macro that splits the cells that have Hard returns inside all
the
tables in my current document into separate rows. Someone sent me this
macro
below to perform this function.

If I need this macro to operate only on the current Cell where my
cursor
is
and not all the tables in my document, how should I modify this?


Macro Below:

Sub RowSplit()

For x = 1 To ThisDocument.Tables.Count

For Each r In ThisDocument.Tables(x).Rows

If InStr(1, r, Chr(13)) Len(r.Cells(1).Range) Then

rowsArray = Split(r.Cells(1).Range, Chr(13))
nSubRowCount = UBound(rowsArray)

If nSubRowCount 1 Then
r.Select

For i = nSubRowCount To 1 Step -1
If Len(Replace(rowsArray(i), Chr(7), ""))
0
Then
Selection.InsertRowsBelow
ThisDocument.Tables(x).Cell(r.Index + 1,
1).Range = rowsArray(i)
r.Select
End If
Next
Selection.Range = rowsArray(0)
End If

End If

Next
Next

End Sub






 




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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:32 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.