I am assisting a customer currently using Word 2002 on a Windows 2000 system.
She has a counter macro that is not working like it used to, probably because
she recently was upgraded from Word 2000. The macros are old because they are
in WordBasic format and I was worndering if this may be part of her problem.
The counter refences "counter.txt" for a number to place in the document and
then adds one to the counter for the next user. If a file is opened either
from the new or templates and has not yet been saved the customer gets
prompted to save the file and the counter.txt is placed in the file name box
instead of placing it in the content of the word document. If the document
has been saved first, then it is properly inserted into the body of the
document. I am posting the macro text for reference, any assistance on this
matter would be appreciated.
George
Public Sub MAIN()
Dim choice
Dim YR$
YR$ = Space(255)
Dim COUNTER
Dim fname$
'Display Save Message and store result in choice
choice = WordBasic.MsgBox("Are you sure you want to save this File?", "Save
File", 1)
If choice = -1 Then
'Open file that has counter Value
Open "J:\public\counter\COUNTER.TXT" For Input As 1
'get value from File located in c:\temp\counter.txt
Input #1, YR$, COUNTER
Close #1
' Add 1 to the value
COUNTER = COUNTER + 1
'change value into TEXT
fname$ = YR$ + "-" + Mid(Str(COUNTER), 3)
'Open File to save Counter
Open "J:\public\counter\COUNTER.TXT" For Output As #1
'Save new number to counter File
Write #1, YR$, COUNTER
Close 1
' send File Name to the File Save Dialog
WordBasic.SendKeys fname$
'Open the File Save Dialog Box
WordBasic.FileSave
Else
WordBasic.MsgBox "File did not Save!!!", "Save Error", 16
End If
BYE:
End Sub
Charles Kenyon - 25 Jan 2005 23:07 GMT
I'm not going to examine your code because my analysis would not help you.
Take a look at http://word.mvps.org/faqs/macrosvba/NumberDocs.htm. It may
solve your problem with up-to-date code.

Signature
Charles Kenyon
Word New User FAQ & Web Directory: http://addbalance.com/word
Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide
See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
>I am assisting a customer currently using Word 2002 on a Windows 2000
>system.
[quoted text clipped - 51 lines]
> BYE:
> End Sub
Jonathan West - 26 Jan 2005 00:01 GMT
>I am assisting a customer currently using Word 2002 on a Windows 2000
>system.
[quoted text clipped - 7 lines]
> and
> then adds one to the counter for the next user.
You can do that in VBA as shown in this article
Creating sequentially numbered documents (such as invoices)
http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Klaus Linke - 26 Jan 2005 01:39 GMT
Hi George,
What doesn't work? The only error I see is that you write
Write #1, YR$, COUNTER
to the file counter.txt, so just the number COUNTER is written, while you do
some string manipulation
fname$ = YR$ + "-" + Mid(Str(COUNTER), 3)
on the COUNTER when creating the new file name...
It probably should be simply
fname$ = YR$ + "-" + Str(COUNTER)
Regards,
Klaus
Jezebel - 26 Jan 2005 04:30 GMT
It's the WordBasic.SendKeys instruction that will go wrong. Instead it
should be some sort of Insert statement, or better still set the value of a
document property then update fields.
> Hi George,
>
[quoted text clipped - 10 lines]
> Regards,
> Klaus
Klaus Linke - 26 Jan 2005 04:46 GMT
Worked fine when I tested it... though you're right that it's best avoided.
Instead of
WordBasic.SendKeys fname$
WordBasic.FileSave
you could use
With Dialogs(wdDialogFileSaveAs)
.Name = fname$
.Display
End With
Regards,
Klaus
> It's the WordBasic.SendKeys instruction that will go wrong.
> Instead it should be some sort of Insert statement, or better
[quoted text clipped - 15 lines]
> > Regards,
> > Klaus