Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-13-2014, 02:52 PM
gerrymac gerrymac is offline code to run once only Windows 7 64bit code to run once only Office 2007
Novice
code to run once only
 
Join Date: May 2014
Posts: 5
gerrymac is on a distinguished road
Exclamation code to run once only

Forgive me in advance, but I have a word.dot and have managed to get the code to insert a unique receipt number sequentially into the header of the document on open, trouble is I need to also find a way of stopping the code from running again and again once it has created an invoice number as when ever someone else opens the doc it runs again and the code overwrites the originally created number with a new one, has anyone came across or solved this in the past and knows how to get around it, i thought of using the system date/time but not sure how to implement this



Code:

Code:
  Dim path As String
   
  path = "\Documents\Contracts\"
  Order = System.PrivateProfileString("\Documents\Contracts\settings.txt", "macrosettings", "Order")
  With ActiveDocument.Bookmarks
                                      .Add Name:="Order"
  End With
  If Order = "" Then
                                      Order = 1
  Else
      Order = Order + 1
  End If
   
  System.PrivateProfileString("\\Documents\Contracts\settings.txt", "MacroSettings", _
          "Order") = Order
  ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "7000#")
  'ActiveDocument.SaveAs FileName:=path & Format(Order, "00#")
  End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
code to run once only Need Help with Below Code rsrasc Word VBA 6 04-01-2014 03:42 PM
code to run once only Where does my code go? rbaldwin Word VBA 3 03-14-2012 02:31 PM
code to run once only vbc code rajpeter Excel Programming 2 09-13-2011 02:29 PM
vba code in excel rajpeter Excel Programming 5 09-11-2011 06:13 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:01 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft