Seq Numbering - Macro problem

S

Silena K-K

Hi

I need to set up sequential numbering in a WORD document and tried to follow
the instructions at the following site
http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm however I'm a little lost.

I'm not exactly sure what this line of code means
Order = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "Order")

I cannot create a "settings.txt" file on the c:\drive as I do not have write
access (IT have blocked) and I'm also not sure what the "MacroSettings",
"Order" is?

Please help...Thank you Silena
 
G

Graham Mayor

Settings.txt is a text file that stores the numbers. The macro shows it
saved in the root of the C: drive, but you can change that path to any path
that you have read/write access to and that will not be wiped by network
maintenance, eg your personal document folder or the user templates folder.

Order is the stored number (see example below).

The following is a variation of the similar code from my web site. My macro
uses Settings.ini as the filename, but the principle is exactly the same -
http://www.gmayor.com/automatic_numbering_documents.htm

Sub AddNoFromINIFileToHeader()
Dim SettingsFile As String
Dim Order As String
Dim sView As String
'Save invoice number in the Word user template folder.
SettingsFile = Options.DefaultFilePath(wdUserTemplatesPath) &
"\Settings.ini"
'or for shared access the Workgroup folder
'SettingsFile = Options.DefaultFilePath(wdWorkgroupTemplatesPath) &
"\Settings.ini"

Order = System.PrivateProfileString(SettingsFile, _
"InvoiceNumber", "Order")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If

System.PrivateProfileString(SettingsFile, "InvoiceNumber", _
"Order") = Order
sView = ActiveWindow.View 'store the current view
With ActiveWindow
.View = wdPrintView 'set the document view to print layout
.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With Selection
.WholeStory 'select any existing header text
.Delete unit:=wdCharacter, Count:=1 'and delete it
.Font.name = "Arial"
.Font.Bold = True
.Font.Italic = False
.Font.Size = "10"
.ParagraphFormat.Alignment = wdAlignParagraphRight
.TypeText Text:="Invoice No.: " & Format(Order, "#")
End With
.View.SeekView = wdSeekMainDocument
.View = sView
End With
End Sub


You can use the same settings file to store a variety of information for
other purposes - eg to store user details for inclusion in a document. A
settings file laid out as follows could be used with the macro below to
insert user details in a document. The settings file also includes the
Invoice number and a variety of other information you could utilise in your
macros.

[InvoiceNumber]
Order=2795
Count=3
[Print Number]
Order=1
[UserName]
Name = "Graham Mayor"
Address = "1 Any Street, 8000 Anytown, Cyprus"
Address1 = "1 Any Street,"
Address2 = "8000 Anytown,"
Address3 = "Cyprus""
Phone = "00 111111"
Email = "(e-mail address removed)"
[CertificateNumber]
Order=123


Sub AddDataFromINIFile()
Dim SettingsFile As String
Dim name As String
Dim Address As String
Dim EMail As String
Dim Phone As String
Dim lBreak As String

SettingsFile = Options.DefaultFilePath(wdUserTemplatesPath) &
"\Settings.ini"

name = System.PrivateProfileString(SettingsFile, _
"UserName", "Name")
Address = System.PrivateProfileString(SettingsFile, _
"UserName", "Address")

lBreak = "," & vbCr
Address = Replace(Address, ", ", lBreak)

Phone = System.PrivateProfileString(SettingsFile, _
"UserName", "Phone")
EMail = System.PrivateProfileString(SettingsFile, _
"UserName", "Email")

With Selection
.TypeText Text:=name
.TypeParagraph
.TypeText Text:=Address
.TypeParagraph
.TypeText Text:=Phone
.TypeParagraph
.TypeText Text:=EMail
End With
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top