Word 2003
I have written (with the help of others as I am not any good at it) some
code to insert a Purchase Order Number in sequence. This is done by
accessing a menu within Word called template tools.

Everything works fine if you go to File, Open, Select the relevant template,
Click Open and *Enable Macros*. The same happens if you go to File New, From
Existing document, select the relevant template, Click Open *Enable Macros*.

However, if you use File New, and select it from either the recently used
files list it does not work and although the file opens - when you try to
insert the PO number you get the following error

Microsoft Visual Basic
System Error &H80004005 (-2147467259). Unspecified Error.

Is this to do with the "Enabling Macros" bit or what do you think? I could
(with help - please ;-) ) write some code within this to ensure that macros
are enabled on opening the file??? What do you think?

here is a copy of the code:


Sub AddPONo()

Order = System.PrivateProfileString("\\server\folder\IT\Purchase
Orders\Settings.Txt", _
"MacroSettings", "Order")

If Order = "" Then
Order = 508
Else
Order = Order + 1
End If

System.PrivateProfileString("\\server\folder\IT\Purchase
Orders\Settings.txt", "MacroSettings", _
"Order") = Order

ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "IT00000#")
ActiveDocument.SaveAs FileName:="\\server\folder\IT\Purchase Orders\" &
Format(Order, "IT00000#.doc")

End Sub




Sub AutoOpen()
Dim aStory As Range
Dim aField As Field
For Each aStory In ActiveDocument.StoryRanges
For Each aField In aStory.Fields
aField.Update
Next aField
Next aStory
End Sub


Thanks in advance for any help/advise you can offer. If you need any more
infomation - please let me know

Thanks again

Sarah x

Re: Help by Jonathan

Jonathan
Mon Apr 16 11:36:48 CDT 2007

Hi Sarah,

This problem is probably nothing to do with your code, but is more likely to
do with the fact that you have edited the code many times and are suffering
from a touch of template bloat. Take a look here.

Combatting Template Bloat
http://www.word.mvps.org/FAQs/MacrosVBA/TemplateBloat.htm

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org


"Sarah_Lecturer" <SarahLecturer@discussions.microsoft.com> wrote in message
news:A812E630-8B9C-45C1-8D5C-4683E9EC5BF9@microsoft.com...
> Word 2003
> I have written (with the help of others as I am not any good at it) some
> code to insert a Purchase Order Number in sequence. This is done by
> accessing a menu within Word called template tools.
>
> Everything works fine if you go to File, Open, Select the relevant
> template,
> Click Open and *Enable Macros*. The same happens if you go to File New,
> From
> Existing document, select the relevant template, Click Open *Enable
> Macros*.
>
> However, if you use File New, and select it from either the recently used
> files list it does not work and although the file opens - when you try to
> insert the PO number you get the following error
>
> Microsoft Visual Basic
> System Error &H80004005 (-2147467259). Unspecified Error.
>
> Is this to do with the "Enabling Macros" bit or what do you think? I
> could
> (with help - please ;-) ) write some code within this to ensure that
> macros
> are enabled on opening the file??? What do you think?
>
> here is a copy of the code:
>
>
> Sub AddPONo()
>
> Order = System.PrivateProfileString("\\server\folder\IT\Purchase
> Orders\Settings.Txt", _
> "MacroSettings", "Order")
>
> If Order = "" Then
> Order = 508
> Else
> Order = Order + 1
> End If
>
> System.PrivateProfileString("\\server\folder\IT\Purchase
> Orders\Settings.txt", "MacroSettings", _
> "Order") = Order
>
> ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order,
> "IT00000#")
> ActiveDocument.SaveAs FileName:="\\server\folder\IT\Purchase Orders\" &
> Format(Order, "IT00000#.doc")
>
> End Sub
>
>
>
>
> Sub AutoOpen()
> Dim aStory As Range
> Dim aField As Field
> For Each aStory In ActiveDocument.StoryRanges
> For Each aField In aStory.Fields
> aField.Update
> Next aField
> Next aStory
> End Sub
>
>
> Thanks in advance for any help/advise you can offer. If you need any more
> infomation - please let me know
>
> Thanks again
>
> Sarah x