MultSequentially numbering multiple copies Macro error

P

Pamela

I'm am new in using Macro's, I needed to number copies of the same document, I tried to use the above macro. I get an error at
SerialNumber = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "SerialNumber")

It says varible not defined. I named the bookmark "SerialNumber", but named the macro PrintSerialNumber, tried to change macro name to SerialNumber, but didn't work. I wrote the code like was on the web site. Did I miss a step, name my macro wrong?? I did get the code to work on another computer, it didn't have Option Explicit at the top. Both run msword 2000.
Any help would be appreciated.
 
J

Jean-Guy Marcil

Hi Pamela,

If it worked on the macine that did not have Option Explicit, does this
means that it fails on your machine where you do have Option Explicit at
the top?
If you have Option Explicit , do declare all your variable explicitly, in
particular "SerialNumber"?
Option Explicit means that you have to declare all variables explicitly.
You should have something like:

Dim SerialNumber As String

at the begining of yout code.
Is this the problem?
--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org


Pamela said:
I'm am new in using Macro's, I needed to number copies of the same
document, I tried to use the above macro. I get an error at
SerialNumber = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "SerialNumber")

It says varible not defined. I named the bookmark "SerialNumber", but
named the macro PrintSerialNumber, tried to change macro name to
SerialNumber, but didn't work. I wrote the code like was on the web site.
Did I miss a step, name my macro wrong?? I did get the code to work on
another computer, it didn't have Option Explicit at the top. Both run msword
2000.
 
P

Pamela

Thanks that helped on that error. Now I have another.
Counter = 0 variable not defined. I don't know what to define it as. Is Option Explicit needed if not is there any way to remove it. Thanks again.
 
J

Jean-Guy Marcil

Hi Pamela,

Most programmers will tell you that it is better to keep the "Option
Explicit" line there. For very short modules, it does not really matter, but
for very long ones it can help sort out/prevent mistakes that would
otherwise be hard to trace. So, it is a good habit to start using it when
you start programming in VBA.

Dim Counter As Long

is probably what you want.

To find out more about variables, or any other VBA topic, while in the VBE
window, select/highlight a code word, such as Dim, then hit F1 to get to the
help page for that word.
With Dim, you will learn about variables and their declaration. It is also a
good idea to check out the other topics under "See also..." (top left corner
of the help page).

HTH
--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org


Pamela said:
Thanks that helped on that error. Now I have another.
Counter = 0 variable not defined. I don't know what to define it as. Is
Option Explicit needed if not is there any way to remove it. Thanks again.
 

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