Wordbasic conversion

G

George Wilson

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
 
J

Jonathan West

George Wilson said:
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.

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
 
K

Klaus Linke

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
 
K

Klaus Linke

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
 

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