MYSTERY: Saving template deletes bookmark

  • Thread starter NZ VBA Developer
  • Start date
N

NZ VBA Developer

G'day!

Has anyone encountered this before? I insert a bookmark in the main story of
my template. As far as I can tell there's nothing special about the template
or the bookmark - altho I can't say for certain; I inherited the template
from a long-departed source. Every time I save the template the bookmark gets
deleted automagically. Bit of a buggar that 'cuz I really need that bookmark
to be there in the final document.

BTW, it's only the bookmark in the main story of the template that gets
deleted. I have 6 or 7 more in the header and footer and those don't get
touched.

Any Sherlocks out there that can solve this mystery?
 
S

Shauna Kelly

G'day

I assume there's no code running in this template that could cause the
problem.

If this were mine, I would first rule out an extraneous (and very badly
behaved!) add-in. Try starting Word in safe mode (winword.exe /a). Create
the bookmark, save and re-open. Is the bookmark still there? If so, then you
job is to identify which global template or add-in is the culprit. Ignore
the name of the article and read here for ways to identify all loaded
add-ins:
http://office.microsoft.com/en-au/word/HA011514521033.aspx?pid=CL100636481033

Shauna
(Also in deep mourning!)


Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
N

NZ VBA Developer

Shauna,

All the code in the template is mine. I dumped the original code first
thing. Ya never know what sort of stunts the last cowboy might have pulled.
<g>

I'm pretty sure it's not an add-in either; with the exception of Adobe
Acrobat, they're all mine as well and have never given me any problems
before. Besides I've got nothing in any of them around the Save event anyway.

I should probably add that this is the _only_ template that this happens on
and that it happens on the save and not just the close. In fact, I can watch
it disappear: Click File | Save ... hourglass ... no more bookmark! (Altho I
just checked and it does go missing if I close - and save changes - and
reopen as well.)

I even tried giving it a different name but same result. And I tried closing
and restarting Word and even restarting my computer. Next test: put it on the
wife's machine. If that doesn't fix it then I guess I'll try rebuilding the
template from scratch... ~sigh~ ...this project is never gonna be finished...
 
H

Helmut Weber

Hi NZ VBA Developer,

I read about that in the German groups.
As long as I followed the thread,
nobody came up with a solution.

You sure know about possible workarounds,
like storing start and end of the bookmark
and the name in doc-variables and recreating
it at doc-open.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
N

NZ VBA Developer

OK, it’s definitely this particular template – although now it’s just
happening when I close and reopen, not when I save. Here’s what I’ve done so
far to narrow it down:

1. I put the template on Mrs. Koder’s Komputer, inserted the bookmark;
saved and the bookmark stayed; closed and reopened and the bookmark
disappeared. No help.

2. I put the template back on my machine; started Word in safe mode;
inserted the bookmark; saved the template and the bookmark stayed; closed and
reopened the template and the bookmark disappeared. No help - although it did
elimate any add-ins.

3. I thought maybe it had something to do with the custom style of the
paragraph at the insertion point so I added another paragraph (this is
important) and set the style to Normal. (Normal is just plain old Arial 12 pt
NZ English.) Moved the bookmark to this line; saved and the bookmark stayed;
closed and reopened and the bookmark stayed. A little progress...

4. I moved the bookmark back to the original location on the paragraph with
the custom style; saved and the bookmark stayed; closed and reopened and the
bookmark _stayed_. A bit more progress...

5. I deleted the second paragraph and changed the style of the first
paragraph to Normal; saved and the bookmark stayed; closed and reopened and
the bookmark disappeared. Not the style. (This is also important.)

6. I thought maybe it was just because there was only one paragraph so I
created a new document; inserted a bookmark; saved and the bookmark stayed;
closed and reopened and the bookmark stayed. Not just because there’s only
one paragraph.

7. I thought maybe it was because it’s a _template_ with just one paragraph
so I converted my doc from above into a template; saved and the bookmark
stayed; closed and reopened and the bookmark stayed. Not because it’s a
template with just one paragraph.

8. Back to the original template. Had a bit more of a play around with the
number of paragraphs and the styles. One paragraph and the bookmark
disappears; more than one paragraph and the bookmark stays. Location (para 1
or para 2 – if there is one) makes no difference, nor does the style or
either paragraph.

Conclusion: It’s definitely just this template and only when it has one
paragraph in it.

I have a couple of workarounds. First I could just add another paragraph to
the template and put the bookmark on the first paragraph. However, I only
really need one paragraph; all the rest of the content will be added using
native Word functionality or a few (very simple, safe and bulletproof) tools
from the template. Plus I worry about the extra paragraph pushing over onto
an extra page. I guess I could make it 1pt and hidden.

Alternatively, since the bookmark is only used to set focus to the start of
the document after the code runs, I could – and probably will – just use
Selection.Homekey. However, I’d still like to know why this is happening in
the first place.

I’ll run a couple more tests tomorrow – after I’ve has some sleep – and let
you know how I get on. If all else fails I guess I’ll just recreate the
template afresh. Well, not completely; I’ll still use the graphic elements
from the original, and I don’t really fancy writing all the code again…
~sigh~ … this project is never gonna end…

FYI: I’m running Word 2003 Pro on WinXP SP2.

--
Cheers!

The Kiwi Koder
A drop goal by Luke McAlister from 50 metres in the 80th minute. Yeah,
that's the ticket...
 
N

NZ VBA Developer

Never found a solution, eh Helmut? Well THAT'S encouraging...

I don't need anything fancy by way of a workaround for this project. (See my
previous / subsequent post.) However, I will keep your suggestion in mind
should the need arise in the future.
 
S

Shauna Kelly

Hi

Curiouser and curiouser!

If you are going to re-build the template then you need the VBA Code cleaner
which can save out all your code modules as separate files, and then you can
import them into the new template. You can get it here:
http://word.mvps.org/FAQs/MacrosVBA/TemplateBloat.htm

However, I don't see why you need a bookmark if there's only one paragraph.
If you just want to position the cursor you can, as you say,
Selection.Homekey. If you want to put text into that first paragraph you can
use (eg) ActiveDocument.Paragraphs(1).range.text = "Fush and chups" (you did
say NZ English, didn't you<g>).

By the way, what's the name of the bookmark?

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
N

NZ VBA Developer

Curiouser indeed, Alice!

The bookmark is called (imaginatively enough) "Start", but it doesn't matter
if I call it "LesBleus" or "HelenClark" or just plain "Bob"; it still gets
deleted when I close and reopen the template - and in the first two instances
I'd be perfectly happy if it did.

Thanks for the pointer to the VBA Code Cleaner. If I do decide to rebuild
the template, it should make the process a lot easier. Not really sure that I
can be bothered though. I guess the only reason I'm tied to using the
bookmark is for consistency. All of the other templates for this project use
this process to set focus to the "starting point" of the document (which may
or may not be the first paragraph), and I didn't want this one to be the odd
one out.

In addition, since all of the other templates do it this way, I was looking
at moving the "set focus" procedure into my global "toolkit" template.
However, even if I do make it a common procedure, I'll need to add some error
handling. All of the templates are designed to be rerun, and the rerun
process references the bookmarks. This is normally a very safe thing to do as
the rest of the bookmarks are in protected sections. However, the "Start"
bookmark is not and so could potentially be deleted. Thus the safety net
should probably be to check for the existence of the bookmark and use
Selection.Homekey if it's not there.

And for the record, I NEVER say "fush and chups" or even "feesh n cheeps".
I'll let you in on a little secret: I'm actually just a Plastic Kiwi -
American by birth but living in Godzone since 2000. Consequently, I talk
proper like: "fish and chips, thankuverymuch"... <g>
 
E

Ed from AZ

Just a thought: you don't have anything in an Open or Close sub, or
some tidbit left over from testing/debugging, that accesses this
bookmark, do you? Especially something that would delete anything
already in it, which would delete the bookmark?

Ed
 
N

NZ VBA Developer

Good thought Ed, but no. There are no macros around the Close event, and
while there are macros that touch the other bookmarks in the template (thus
the reason for the bookmarks in the first place), there's nothing that
touches this bookmark - except to select it in a new doc created from the
template - and nothing in the AutoOpen macros that touch any of the
bookmarks. And even the code that touches the other bookmarks doesn't
specifically delete them; they just write text into the bookmark range and
then reinsert the particular bookmark around the range again.

I've pretty much given up on finding an answer as it's not pressing in this
instance. I'll just stick with Selection.Homekey for this one template. Maybe
when I have more time I'll try rebuilding the template from scratch and see
if I can get it working properly then.
 

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