Bryan
Wed Jan 09 19:55:00 PST 2008
Thanks for your help Doug! I copied the code and created the bookmark as
instructed, but I am apparently missing something. According to the macro,
this should run on its own or so it seems. I get nothing at all. I have to
manually run the macro and end up with a type mismatch on the following line:
SerialNumber = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "SerialNumber")
I am using the code as written with the exception of adding the SerialNumber
As Long, Counter As Long as was in the previous entries. I'll later use the
rest of the modifications suggested as I have serial numbers preassigned and
dozens of docs already written that I'll be adding this to. What I am doing
now is practicing on a blank doc so I can understand how it all works.
Thanks again!
"Doug Robbins - Word MVP" wrote:
> See the article "Sequentially numbering multiple copies of single document
> using a macro" at:
>
>
http://www.word.mvps.org/FAQs/MacrosVBA/NumberCopiesOf1Doc.htm
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Bryan" <Bryan@discussions.microsoft.com> wrote in message
> news:FA62416C-714C-412E-BAC5-A8DD5C9EF61D@microsoft.com...
> > Thanks Doug, I'll try that. That answers my second question, but I am
> > still
> > not sure how to insert and call the Serial Number field. I tried calling
> > it
> > "Serial Number(s)" and inserting a field MacroButton/serialize, (which is
> > the
> > existing name of the macro.) When I double click on the field in my
> > document
> > it opens up the dialog, (Message boxes,) but after I enter the number of
> > copies to print and starting serial number I get an error, "The requested
> > member of the collection does not exist. As I stated previously, I know
> > zip
> > about using macros in Word. Here is my code as it now stands:
> >
> > Sub Serialize()
> > '
> > ' Serialize Macro
> > ' Macro recorded 01/08/2008 by sna142
> > Dim Message As String, Title As String, Default As String, NumCopies As
> > Long
> > Dim Rng1 As Range, SerialNumber As Long, Counter As Long
> >
> > ' Set prompt.
> > Message = "Enter the number of copies that you want to print"
> > ' Set title.
> > Title = "Print"
> > ' Set default.
> > Default = "1"
> >
> > ' Display message, title, and default value.
> > NumCopies = Val(InputBox(Message, Title, Default))
> > Message = "Enter the starting serial number"
> > Title = "Serial Number"
> > SerialNumber = Val(InputBox(Message, Title, Default))
> >
> > ActiveDocument.Fields.Update
> >
> > Set Rng1 = ActiveDocument.Bookmarks("Serial Number(s)").Range
> > Counter = 0
> >
> > While Counter < NumCopies
> > Rng1.Delete
> > Rng1.Text = SerialNumber
> > ActiveDocument.PrintOut
> > SerialNumber = SerialNumber + 1
> > Counter = Counter + 1
> > Wend
> >
> > 'Save the next number back to the Settings.txt file ready for the next
> > use.
> > System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
> > "Serial Number(s)") = SerialNumber
> >
> > 'Recreate the bookmark ready for the next use.
> > With ActiveDocument.Bookmarks
> > .Add Name:="SerialNumber", Range:=Rng1
> > End With
> > 'Next line added to update { REF SerialNumber }
> > Dim Fld As Field
> > For Each Fld In ActiveDocument.Fields
> > If Fld.Type = wdFieldRef Then Fld.Update
> > Next
> >
> > ActiveDocument.Save
> >
> > End Sub
> >
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> If you name the macro autoopen(), it will run when the document is
> >> opened.
> >>
> >> However, if you want to be able to open the document without the Serial
> >> Number being updated and only have it updated when the document is
> >> printed,
> >> you might be better off putting the code in macros named FilePrint and
> >> FilePrintDefault so that it will run when the document is printed.
> >> --
> >> Hope this helps.
> >>
> >> Please reply to the newsgroup unless you wish to avail yourself of my
> >> services on a paid consulting basis.
> >>
> >> Doug Robbins - Word MVP
> >>
> >> "Bryan" <Bryan@discussions.microsoft.com> wrote in message
> >> news:7DF7B7F3-08A0-472C-AF9E-7084FA60BA41@microsoft.com...
> >> > Hey all! I've inserted the macro and have been playing with it along
> >> > with
> >> > the changes. I must preface that I am completely out of my element
> >> > here.
> >> > I
> >> > am quite proficient with Access but have never worked with Macros in
> >> > Word.
> >> > What I am trying to accomplish in a nutshell is: I have a line on my
> >> > word
> >> > doc
> >> > Serial Number ____________
> >> > How do I call this/name this for the macro to know where to run it and
> >> > can
> >> > this be automatically run when the doc is opened? And if I am simply
> >> > editting the doc and not printing it, can it be canceled?
> >> >
> >> > Thanks in advance,
> >> > Bryan
> >> >
> >> > "Jay Freedman" wrote:
> >> >
> >> >> OK, replace the ActiveDocument.Fields.Update line nearest to the end
> >> >> of the macro with these lines:
> >> >>
> >> >> Dim Fld As Field
> >> >> For Each Fld In ActiveDocument.Fields
> >> >> If Fld.Type = wdFieldRef Then Fld.Update
> >> >> Next
> >> >>
> >> >> This is more selective than just updating all the fields; in
> >> >> particular, the Ask fields (which have .Type = wdFieldAsk) won't be
> >> >> updated the second time.
> >> >>
> >> >> On Thu, 13 Sep 2007 11:06:01 -0700, Code Numpty
> >> >> <CodeNumpty@discussions.microsoft.com> wrote:
> >> >>
> >> >> >Almost there.
> >> >> >All works a treat except, as you said Jay, the ask fields fire their
> >> >> >pop-ups
> >> >> >again at the end.
> >> >> >
> >> >> >"Jay Freedman" wrote:
> >> >> >
> >> >> >> To solve the first problem, delete the lines
> >> >> >>
> >> >> >> > >If SerialNumber = "" Then
> >> >> >> > > SerialNumber = 1
> >> >> >> > >End If
> >> >> >>
> >> >> >> You don't need them any more after you change to getting the
> >> >> >> SerialNumber
> >> >> >> from the Val function. (The expression If SerialNumber = "" checks
> >> >> >> whether
> >> >> >> it's an empty string, but now SerialNumber is a number, not a
> >> >> >> string.)
> >> >> >>
> >> >> >> To solve the second problem, put another
> >> >> >> ActiveDocument.Fields.Update
> >> >> >> statement into the macro where you just removed the three lines.
> >> >> >> That
> >> >> >> should
> >> >> >> cause the Ask fields to fire their popups. If the Ask fields pop up
> >> >> >> again at
> >> >> >> the end of the macro, you'll need some more code to fix that. (I
> >> >> >> usually
> >> >> >> avoid Ask fields because they're so pesky.)
> >> >> >>
> >> >>
> >> >> --
> >> >> Regards,
> >> >> Jay Freedman
> >> >> Microsoft Word MVP FAQ:
http://word.mvps.org
> >> >> Email cannot be acknowledged; please post all follow-ups to the
> >> >> newsgroup
> >> >> so all may benefit.
> >> >>
> >>
> >>
> >>
>
>
>