PC Review


Reply
Thread Tools Rate Thread

Can anyone help on a macro problem that I have

 
 
tweacle
Guest
Posts: n/a
 
      5th Jan 2008

I have the following macro that im using with a set up to automatically
increase no's by 1 everytime they print.

Sub PrintAndNumber()
Dim prty As DocumentProperty
Dim bFound As Boolean
Const strPropertyName = "Ref Number"

For Each prty In ActiveDocument.CustomDocumentProperties
If UCase$(prty.Name) = UCase$(strPropertyName) Then
bFound = True
Exit For
End If
Next prty
If Not bFound Then
Set prty =
ActiveDocument.CustomDocumentProperties.Add(strPropertyName, False,
msoPropertyTypeNumber, 1)
End If
Do
ActiveDocument.Fields.Update
ActiveDocument.PrintOut
ActiveDocument.CustomDocumentProperties(strPropertyName).Value
= ActiveDocument.CustomDocumentProperties(strPropertyName).Value + 1
Loop Until
ActiveDocument.CustomDocumentProperties(strPropertyName).Value 5
End Sub

The problem im having is when I first run it its fine. When I save and
close workbook and then run macro again after reopening it dont
completely run it just prints the next no and then stops. Can anyone
help on amending the macro above so that once its completed it saves
and closes document and then when I reopen the document at a later time
it just carries on printing all the sheets increasing the ref no's when
I run the macro. Thanks




--
tweacle
 
Reply With Quote
 
 
 
 
Stefan Blom
Guest
Posts: n/a
 
      10th Jan 2008
Ask in a programming newsgroup such as microsoft.public.word.vba.general for
assistance with this. But see also the following article, which might be
helpful: http://word.mvps.org/faqs/macrosvba/...piesOf1Doc.htm.

--
Stefan Blom
Microsoft Word MVP


"tweacle" wrote:

>
> I have the following macro that im using with a set up to automatically
> increase no's by 1 everytime they print.
>
> Sub PrintAndNumber()
> Dim prty As DocumentProperty
> Dim bFound As Boolean
> Const strPropertyName = "Ref Number"
>
> For Each prty In ActiveDocument.CustomDocumentProperties
> If UCase$(prty.Name) = UCase$(strPropertyName) Then
> bFound = True
> Exit For
> End If
> Next prty
> If Not bFound Then
> Set prty =
> ActiveDocument.CustomDocumentProperties.Add(strPropertyName, False,
> msoPropertyTypeNumber, 1)
> End If
> Do
> ActiveDocument.Fields.Update
> ActiveDocument.PrintOut
> ActiveDocument.CustomDocumentProperties(strPropertyName).Value
> = ActiveDocument.CustomDocumentProperties(strPropertyName).Value + 1
> Loop Until
> ActiveDocument.CustomDocumentProperties(strPropertyName).Value 5
> End Sub
>
> The problem im having is when I first run it its fine. When I save and
> close workbook and then run macro again after reopening it dont
> completely run it just prints the next no and then stops. Can anyone
> help on amending the macro above so that once its completed it saves
> and closes document and then when I reopen the document at a later time
> it just carries on printing all the sheets increasing the ref no's when
> I run the macro. Thanks
>
>
>
>
> --
> tweacle
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Microsoft Excel Programming 0 3rd May 2008 01:03 AM
Macro problem where workbook name is saved in another name and macro reference changes BobR Microsoft Excel Programming 1 22nd Mar 2008 02:44 AM
Color Row Macro Problem, adapted from Patrick Malloy macro =?Utf-8?B?U3RldmVD?= Microsoft Excel Programming 4 21st Jun 2006 12:28 PM
Problem in updating all worksheets of a workbook using a macro that calls another macro saai_ram@yahoo.com Microsoft Excel Programming 3 20th Mar 2006 05:21 AM
Chronic macro problem -How to delete an excel macro Todd Microsoft Excel Crashes 0 30th Jun 2004 05:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:23 PM.