Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-21-2013, 05:09 AM
UniAdmin UniAdmin is offline Sequentially numbering a document Windows 7 64bit Sequentially numbering a document Office 2010 64bit
Novice
Sequentially numbering a document
 
Join Date: Feb 2013
Posts: 1
UniAdmin is on a distinguished road
Default Sequentially numbering a document

I have been trying to add a sequential numbering macro to a word document so that each time it is opened the document is given a new number. The form in question is to record 'near misses' and it would be helpful to be able to open and print off the form each time it was required to be filled in with the next number.



I have tried the code below:
Code:
Sub AutoNew() FormNumber = System.PrivateProfileString("C:\Settings.Txt", _ "MacroSettings", "Order") If FormNumber = "" Then FormNumber = 1 Else FormNumber = FormNumber + 1 End If System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _ "FormNumber") = FormNumber ActiveDocument.Bookmarks("FormNumber").Range.InsertBefore Format(FormNumber, "00#") ActiveDocument.SaveAs FileName:="path" & Format(FormNumber, "00#") End Sub

But I get an error message at the line beginning 'System. Private' telling me that the _ is not a valid character.

Any help gratefully received

Last edited by macropod; 02-21-2013 at 07:09 PM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 02-21-2013, 07:25 PM
macropod's Avatar
macropod macropod is offline Sequentially numbering a document Windows 7 64bit Sequentially numbering a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You code looks OK, though:
• you haven't declared your 'FormNumber' variable;
• "Order" should read "FormNumber";
• your code inserts the form number before the bookmark, rather than updating it, which means any cross-references to the bookmark also won't update to reflect the form number; and
• you may encounter permissions issues trying to write to C:\

For a different approach, see: https://www.msofficeforums.com/word/...iple-docs.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sequentially numbering a document Sequential Document Numbering Geza59 Word VBA 18 01-15-2014 01:43 AM
Sequentially numbering a document Sequential document numbering excel'97 Scottlambert Excel 1 05-11-2012 03:40 AM
Document unique numbering / forms JamesF Word 0 11-22-2010 03:52 AM
Continuous page numbering in a merged document dkeinath Mail Merge 0 07-30-2010 09:30 AM
Please help with Numbering a document with multiple letters. DJReality213 Office 1 01-15-2010 05:56 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:40 PM.


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