Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

Help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sarah_Lecturer - 16 Apr 2007 14:22 GMT
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
Jonathan West - 16 Apr 2007 17:36 GMT
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

Signature

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

> Word 2003
> I have written (with the help of others as I am not any good at it) some
[quoted text clipped - 62 lines]
>
> Sarah x
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.