S
Steve
Hi,
I have designed a form with a seq number running with an autonew macro. The
code has been entered to unprotect>number change>protect. I now wish to add
an address field linked to my outlook address book. Again the code has been
entered in the correct place to protect and unprotect. There are both
succesful on a seperate document but fail together. Is it possible to have
them both work on the same document? The codes i am using are as follows:
Private Sub Document_New()
End Sub
Sub AutoNew()
Order = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "Order")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
System.PrivateProfileString("C:\Settings.Txt", "MacroSettings", _
"Order") = Order
ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "100#")
ActiveDocument.SaveAs FileName:="D:\My Documents\Work\Quotes Past
Month\Quotation ID_" & Format(Order, "100#")
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
-------------------------------------------------------
Public Sub InsertAddressFromOutlook()
Dim strCode As String, strAddress As String
Dim iDoubleCR As Integer
'Set up the formatting codes in strCode
strCode = "<PR_GIVEN_NAME> <PR_SURNAME>" & vbCr & _
"<PR_COMPANY_NAME>" & vbCr & _
"<PR_POSTAL_ADDRESS>" & vbCr
'Display the 'Select Name' dialog, which lets the user choose
'a name from their Outlook address book
strAddress = Application.GetAddress(AddressProperties:=strCode, _
UseAutoText:=False, DisplaySelectDialog:=1, _
RecentAddressesChoice:=True, UpdateRecentAddresses:=True)
'If user cancelled out of 'Select Name' dialog, quit
If strAddress = "" Then Exit Sub
'Eliminate blank paragraphs by looking for two carriage returns in a row
iDoubleCR = InStr(strAddress, vbCr & vbCr)
Do While iDoubleCR <> 0
strAddress = Left(strAddress, iDoubleCR - 1) & _
Mid(strAddress, iDoubleCR + 1)
iDoubleCR = InStr(strAddress, vbCr & vbCr)
Loop
'Strip off final paragraph mark
strAddress = Left(strAddress, Len(strAddress) - 1)
'Insert the modified address at the current insertion point
ActiveDocument.Unprotect
Selection.Range.Text = strAddress
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
End Sub
Many thanks in advanced.
Steve
I have designed a form with a seq number running with an autonew macro. The
code has been entered to unprotect>number change>protect. I now wish to add
an address field linked to my outlook address book. Again the code has been
entered in the correct place to protect and unprotect. There are both
succesful on a seperate document but fail together. Is it possible to have
them both work on the same document? The codes i am using are as follows:
Private Sub Document_New()
End Sub
Sub AutoNew()
Order = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "Order")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
System.PrivateProfileString("C:\Settings.Txt", "MacroSettings", _
"Order") = Order
ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "100#")
ActiveDocument.SaveAs FileName:="D:\My Documents\Work\Quotes Past
Month\Quotation ID_" & Format(Order, "100#")
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
-------------------------------------------------------
Public Sub InsertAddressFromOutlook()
Dim strCode As String, strAddress As String
Dim iDoubleCR As Integer
'Set up the formatting codes in strCode
strCode = "<PR_GIVEN_NAME> <PR_SURNAME>" & vbCr & _
"<PR_COMPANY_NAME>" & vbCr & _
"<PR_POSTAL_ADDRESS>" & vbCr
'Display the 'Select Name' dialog, which lets the user choose
'a name from their Outlook address book
strAddress = Application.GetAddress(AddressProperties:=strCode, _
UseAutoText:=False, DisplaySelectDialog:=1, _
RecentAddressesChoice:=True, UpdateRecentAddresses:=True)
'If user cancelled out of 'Select Name' dialog, quit
If strAddress = "" Then Exit Sub
'Eliminate blank paragraphs by looking for two carriage returns in a row
iDoubleCR = InStr(strAddress, vbCr & vbCr)
Do While iDoubleCR <> 0
strAddress = Left(strAddress, iDoubleCR - 1) & _
Mid(strAddress, iDoubleCR + 1)
iDoubleCR = InStr(strAddress, vbCr & vbCr)
Loop
'Strip off final paragraph mark
strAddress = Left(strAddress, Len(strAddress) - 1)
'Insert the modified address at the current insertion point
ActiveDocument.Unprotect
Selection.Range.Text = strAddress
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
End Sub
Many thanks in advanced.
Steve