R
Robin
Hi All,
I have a word template form that we use for quotations. I have created a
macro to unlock, insert an auto number, save the document and relock the form
(works fine). However when i open the newly created doc the autonumber macro
runs again. Can anyone suggest how i can check to see if the document
contains a number already and if so do not run the macro? My code so far is:
Sub AutoOpen()
'
' AutoOpen Macro
'
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:="22747"
End If
'Create and insert the quotation number
Order = System.PrivateProfileString("S:\Public
Access\Quotations\Settings.Txt", _
"MacroSettings", "Order")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
System.PrivateProfileString("S:\Public Access\Quotations\Settings.Txt",
"MacroSettings", _
"Order") = Order
ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "#")
ActiveDocument.SaveAs "S:\Public Access\Quotations\quotation_" &
Format(Order, "#")
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="22747"
End If
Thanks for your help.
Rob
I have a word template form that we use for quotations. I have created a
macro to unlock, insert an auto number, save the document and relock the form
(works fine). However when i open the newly created doc the autonumber macro
runs again. Can anyone suggest how i can check to see if the document
contains a number already and if so do not run the macro? My code so far is:
Sub AutoOpen()
'
' AutoOpen Macro
'
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:="22747"
End If
'Create and insert the quotation number
Order = System.PrivateProfileString("S:\Public
Access\Quotations\Settings.Txt", _
"MacroSettings", "Order")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
System.PrivateProfileString("S:\Public Access\Quotations\Settings.Txt",
"MacroSettings", _
"Order") = Order
ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "#")
ActiveDocument.SaveAs "S:\Public Access\Quotations\quotation_" &
Format(Order, "#")
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="22747"
End If
Thanks for your help.
Rob