Finding the previous line

J

Jean-Guy Marcil

Bonjour,

Dans son message, < James > écrivait :
In this message said:
No, because if I fiddle with the length of the word preceding the
table, the tablerange.start result changes as a result.

I have just tried both Helmut and Jeff's code and everything works as
expected.
So, I am sorry but you are doing something wrong or there is something wrong
with your document, maybe your table is corrupted. Have you tried to test
the code on a brand spanking new document? Type a few words, hit enter,
insert a table, select it and run either Helmut or Jeff's code. Does that
work? If so, your previous document is corrupted in some way or there is
something going on that you are not aware of that gives the result you are
seeing.

If you want you can send me your document with the code and I will have a
look at it.

Just un-mangled my email in my signature.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
H

Helmut Weber

Hi Jeff!
First, You are right.
Second, here is my excuse and an explanation.
As this group is about programming,
I coded what you suggested, (which was my fault):
If a table is at the very start of a document, then
Selection.HomeKey unit:=wdStory
Selection.TypeText Text:=vbCr
or
Selection.Range.InsertBefore vbCr
or
ActiveDocument.Tables(1).Range.InsertBefore vbCr
.... and... and... and
all insert vbCr into the first cell.
Splitting the table however, does the job, or
SendKeys "{ENTER}". I wonder ...
And there are more mysteries about tables.
---
Have a nice day.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
H

Helmut Weber

Hi Jeff,
as I am really concerned about this,
did you read my answer (accidentally as a reply to James),
about Word's different behaviour when typing "Enter" and
inserting VbCr?
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
H

Helmut Weber

Hi Jean-Guy,
are you still following this thread?
I am very interested in your thoughts on
explaining why typing "enter" would behave differently
from inserting vbcr.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Helmut Weber > écrivait :
In this message said:
Hi Jean-Guy,
are you still following this thread?
I am very interested in your thoughts on
explaining why typing "enter" would behave differently
from inserting vbcr.

Weird indeed!
I tried all of the following:

Selection.TypeText vbCrLf
Selection.TypeText Chr(13)
Selection.TypeParagraph

Dim MyRge As Range

Selection.Collapse
Set MyRge = Selection.Range
MyRge.InsertBefore vbCrLf
MyRge.InsertBefore Chr(13)
MyRge.InsertParagraphBefore

SendKeys "~"

And only the SendKeys worked.

I guess that when you do a real "Enter", Word does some work to see where
you are and where you are going. If you are at the position "0" of the first
cell of the first row in a table, you get the "Split Table" command. But
through VBA, Word does as it is told, no assessing of the cursor location.
You want a vbCrLf, you get a vbCrLf!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jeff

Yes I got it

I did the obvious and macro-recorded the manual technique

What do you know... This was recorded!!

Selection.HomeKey Unit:=wdStory
Selection.SplitTable

This code also works

SendKeys "^{HOME}{ENTER}"

....UNLESS you try to run it from the VBA editor using F8
 
J

Jeff

While I've got you ear, I have some strange behaviour with Word 2000

Each time it exits, it saves Normal.dot and records the file in the recent
file list!! Sometimes Word crashes if I've tested a macro in Normal.dot and
saved the template (like I did in response to your last email)

This behaviour has developed in the last week
 
H

Helmut Weber

Hi Jeff,
just didn't want to let your posting unanswered,
but strictly speaking, no idea. There are so many different
approaches. E.g. adding normal.dot to the recent files list
seems to be Word's regular behaviour, if you open normal.dot
directly. What I probably didn't do for some years.
All I do is open a document, [alt F11], write the code,
run the code, close the doc.
Saving or not makes no difference, if
Options.SaveNormalPrompt = false
---
No crashes, as far as normal.dot is concerned, for a long, long time.
But as most of what I code is not worth to be preserved,
it is only minor samples for the newsgroups, ;-)
I overwrite my (test)normal.dot every week or so with the
(real)normal.dot, the hard core of the code I make a living from,
and start from scratch.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
J

Jeff

And why does that surprise you?

the start of the tablerange is measured as an offset from the beginning of
the DOC. If you insert or remove text then the start of the range will
change accordingly!

Anyway, the code is checking for an offset of ZERO - ie the table is at the
start of the DOC
 

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