Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word VBA Help

Status
Not open for further replies.

averilp

Technical User
May 17, 2004
6
GB
Hello,

I'm not that good with Word VBA (Excel is more my thing).

I was given the mission to update some templates by adding new offices to the form(s) which had a mass of spaghetti code. I'm not giving them a complete overhaul because we are changing them soon.

However, I'm confused about the attached file... When you open it directly as a template it looks correct and works, however when you open as a new file from the template, my text box in the footer disappears and is replaced with another one (the old one I am replacing) that has a series of fields (if statements depending on if statements) in it.

I have deleted the offending text box loads of times but it still reappears!

I have tried putting STOP in at the beginning of the AutoNew code and stepping through from that point but even at that point if you go and look at the document the text box change has already occurred.

I'm so confused! Can anyone please have a look and see what might be going on?

Cheers,
Averil
 
I've only had a very quick look at this but the fields in the footer are in the template - the results only show when the variables are set but the fields are there. If you don't want them, delete them - I don't think there's any code that depends on them.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Thanks, but the issue is that I have created the text box with the fields in it that I want (i.e. <Legal_Entity_Name> is a member of the Lloyd's Register Group... etc.)

However, when you open from the template a new text box (which I have deleted in the template and is the old one I want gone) is created that contains a lot of calculated fields (IF <CompanyOption> is blank, then xxx... etc).

Try opening via File Open and you will see the template as I want it, rather than opening through say Windows Explorer.

I hope that makes sense!

Averil
 
You have got, in total, three tetboxes in the footer - but there seems to be something odd with the template as it just crashed Word (2007) for me.

One of the textboxes doesn't seem to want to make itself visible, but you can access it in code. You might find these lines of code useful:

Code:
[blue]ActiveDocument.Sections(1).Footers(1).Shapes(#n).Select ' or ..

ActiveDocument.Sections(1).Footers(1).Shapes(#n).Delete[/blue]

Shapes 1, 2, and 5 are textboxes. Perhaps deleting #5 will help - I'm not entirely sure what yoiur code is filling in.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
What an interesting file.

If I delete the textboxes in the .DOT file (first saved as a new one so I can keep the original), they do not appear in any document cloned from the .DOT file.

I am a bit confused though.

"However, when you open from the template a new text box (which I have deleted in the template and is the old one I want gone) is created that contains a lot of calculated fields (IF <CompanyOption> is blank, then xxx... etc)."

That sounds like you deleted it in the template, but you say you are still getting it. This does not happen for me.

"the issue is that I have created the text box with the fields in it that I want (i.e. <Legal_Entity_Name> is a member of the Lloyd's Register Group... etc.) "

THAT sounds like you have a different textbox - but a textbox none the less.

Are you say you deleted an existing textbox in the .DOT file, made a NEW textbox (in the .DOT file) and you are getting the old one?

Gerry
 
Hi Gerry,

Quote:
"Are you say you deleted an existing textbox in the .DOT file, made a NEW textbox (in the .DOT file) and you are getting the old one? "

Indeed I am saying that. I deleted the offending text box in the .DOT file and created a new one. When a "new" file is created from this .DOT file the new text box is deleted and replaced with the old one.

The text box I want to keep has the following:

<Legal_Entity_Name> is a member of the Lloyd’s Register Group.
<Legal_Entity_Number>
Registered address: <Legal_Entity_Long_Address_1><Legal_Entity_Long_Address_2> <Legal_Entity_Long_Address_3><Legal_Entity_Long_Address_4>


But I am getting the old one with lots of calculated fields for the display of the legal entity name, number and address.

Thanks for looking at this!

Averil
 
I can not duplicate this with the file. If I delete the textbox from the .DOT file - and leave the footer empty - when I clone a new document...there is no textbox. It is deleted from the .DOT file, and it is not in any new document. There is no old textbox.

Gerry
 
Strange strange strange... I will try it on another computer - maybe I just have gremlins in my machine because it is still happening for me :-(
 
I really don't want to delve into the code any more than necessary, and I'm not sure the answer is in there. You seem to have ignored my last reply - let me try and be more specific. On a copy of the template, open it for editing, edit the footer and then go to the VBE Immediate pane and enter: [blue][tt]ActiveDocument.Sections(1).Footers(1).Shapes(1).Delete[/tt][/blue], close the template and see if it solves your problem. If not, then on another copy of the original do the same thing, except run this command: [blue][tt]ActiveDocument.Sections(1).Footers(1).Shapes(1).Delete[/tt][/blue]. Does that solve your problem? if neither works, come back and I'll look a bit further.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Thanks Tony,

Sorry I didn't reply earlier. I thought I had tried that when I first saw your message but I must have been imagining it.

OK that seems to have fixed the problem so far so now I just need to recreate the one that I want to keep and (crossed fingers) it will work :)

Cheers!,
Averil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top