Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Aug 2002
    Location
    Houston, Texas, United Arab Emirates
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Templates & Outlook (Word 2000)

    I would like to have a template for fax covers that will run from a macro. I want to be able to collect the name and fax number from Outlook (Office 2000) as this is where we spend much time keeping our records current. I cannot find how to get this accomplished. I do not like the fax wizard, too many steps. This seems so simple and I am so lost. Can someone please clue me on on what I'm missing. I have had experience with macros and templates with other software, but we are changing our entire system to Microsoft. Thank you so much, Nancy

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Templates & Outlook (Word 2000)

    In Word, the Address Book feature (which you can add using Tools|Customize... under Insert, or find inside the Envelopes dialog) gives you partial access to Outlook, but it normally doesn't insert the fax number. You can customize the hidden AutoText entry that defines the format; there are earlier posts on this board that describe how to do that, and how to find out whether it is an option.

    The second possibility is to write a macro that will perform precisely the steps you want. Because doing a search in an Outlook folder requires learning some arcane methods, I don't recall doing it and don't have any sample code on hand. Again, though, it's likely that there is an earlier example in the Lounge.

    The third method is to start from Outlook, "select" the desired contact in a folder view, and use Outlook's merge feature to merge the contact with your fax cover. This would require that you set up the fax cover template with a couple of merge fields. This process has been discussed in more detail on the Outlook board, and probably is the fastest way to get information into Word that Word's address book doesn't list among its options.

    Hope this gives you some ideas.
    Attached Images Attached Images

  3. #3
    New Lounger
    Join Date
    Aug 2002
    Location
    Houston, Texas, United Arab Emirates
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Templates & Outlook (Word 2000)

    Thank you so much for the info. I'll be digging around older posts this eve, but if anyone can steer me to a specific Post or site, I certainly will be grateful.

    Nancy

  4. #4
    Lounger
    Join Date
    Aug 2002
    Location
    Oklahoma City, Oklahoma, USA
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Templates & Outlook (Word 2000)

    This brought back some not so fond memories. A fax cover sheet was my first project. It took me a lot of work and time and the purchase of a couple of books to figure out how to do it, but I learned a lot in the process. This is my code that refers to a userform called frmInfo which has textboxes that refer to the variables that begin with tbx for textbox. You get the name and fax number from the address book if they are there, otherwise you go to the form and type them in, along with a "RE" and Message and whether the original will follow and the number of pages. Once you have the variables, you click ok and plug them into the template doc at the bookmarks. This code works GOOD and I am proud of it. The only thing is I resorted to using line numbers which is supposed to not be good programming form. If anybody sees a way to make it more elegant, I would appreciate any help.

    Option Explicit ' all variables must be declared
    '
    Dim AddProp As String 'AddressProperties param for Contacts extract routine
    ' c prefix on variables means from contacts
    Dim cName_Number As String ' contact name plus fax number
    Dim NameLength As Integer ' the length of the name part of addprop
    Public cName As String ' public so pass to form
    Public cFaxNum As String ' public so pass to form
    Dim iNumChar As Integer
    Dim iParen As Integer
    Dim strParen As String
    Dim MsResp As Integer
    '
    Sub AutoNew()
    ' The AutoNew macro runs when double click on the fax cover template (dot) file

    'Initialize variables
    AddProp = ""
    cName_Number = ""
    NameLength = 0
    cName = ""
    cFaxNum = ""
    iNumChar = 0
    iParen = 0
    strParen = ""

    ' Go to Address Book to get fax number
    AddProp = "<PR_DISPLAY_NAME>" & "<PR_BUSINESS_FAX_NUMBER>"
    cName_Number = Application.GetAddress("", AddProp, False, 1, , , False, False)
    iNumChar = Len(cName_Number)
    If iNumChar = 0 Then GoTo NoInitFrm ' if user hits the cancel button in AddrBook

    ' fax number length always equals 14
    ' new Contact supplies default area code if only 7 numbers typed in
    If iNumChar < 14 Then GoTo NoFaxNum ' there is a name but no fax number

    ' trap case of name being longer than 14 characters
    ' by testing for left parenthesis character
    iParen = iNumChar - 13 'the 14th character from the right
    strParen = Mid(cName_Number, iParen, 1) 'get one character
    If strParen <> Chr$(40) Then GoTo NoFaxNum ' chrs$(40) equal left parenthesis

    ' if above tests failed then we have a good name and fax number
    GoTo Init_Form '

    ' code that runs if Cancel out of Address Book
    NoInitFrm:
    ' Go to form with no name or number
    Load frmInfo
    frmInfo.tbxFaxTo.SetFocus ' set focus on first text box
    frmInfo.Show
    Exit Sub

    ' Handle situation where there is a name but no fax number
    NoFaxNum:
    Load frmInfo
    frmInfo.tbxFaxTo.Text = cName_Number ' cName_Number will equal name only since there is no fax number
    ' Set the focus on tbxFaxNumber
    frmInfo.tbxFaxNumber.SetFocus
    frmInfo.Show
    Exit Sub

    Init_Form:
    ' Get here only if there is a name and a fax number in cName_Number
    ' Truncate the contact data
    cFaxNum = Right$(cName_Number, 14) 'fax number is always 14 characters long
    NameLength = iNumChar - 14 'the length of the name part of addprop
    cName = Left$(cName_Number, NameLength)

    ' Initialize the UserForm
    Load frmInfo
    'Populate tbx with name and number
    frmInfo.tbxFaxTo.Text = cName
    frmInfo.tbxFaxNumber.Text = cFaxNum
    ' Set the focus on re box since already have name and number filled in
    frmInfo.tbxRe.SetFocus
    frmInfo.Show

    End Sub

    FOLLOWING IS THE CODE FOR THE USERFORM, AS OPPOSED TO THE AUTONEW
    ' This form named frmInfo is loaded and displayed by the AutoNew macro in module Main
    '
    Sub btnCancel_Click()
    ' Code to run when cancel button is clicked
    Unload Me
    End Sub

    Sub btnOK_Click()
    ' Code to run when OK button is clicked
    ' Check for critical empty textboxes
    If (tbxFaxNumber.Text = "") Then
    MsgBox "Please enter the fax number", , "No Fax Number"
    tbxFaxNumber.SetFocus
    Exit Sub
    End If
    If (tbxFaxTo.Text = "") Then
    MsgBox "Please enter the name", , "No TO info"
    frmInfo.tbxFaxTo.SetFocus
    Exit Sub
    End If

    On Error GoTo ErrorHandler

    ' Insert the information into the bookmarks
    With ActiveDocument
    ProtectType = .ProtectionType

    ' If the document is protected, you have to
    ' unprotect it in order to fill the bookmarks
    If Not (ProtectType = wdNoProtection) Then
    .Unprotect
    End If
    End With

    ' Update Bookmarks
    ActiveDocument.Bookmarks("FaxNumber").Range.Text = tbxFaxNumber
    ActiveDocument.Bookmarks("FaxNumber2").Range.Text = tbxFaxNumber
    ActiveDocument.Bookmarks("FaxTo2").Range.Text = tbxFaxTo
    ActiveDocument.Bookmarks("MessageText").Range.Text = tbxMessageText
    ActiveDocument.Bookmarks("Re2").Range.Text = tbxRe

    ' Do the number of pages only if it was filled in
    If (tbxNumberPages <> "") Then
    ActiveDocument.Bookmarks("Pages").Range.Text = tbxNumberPages
    End If

    ' Process Original will Follow
    If (OrigYes = True) Then
    ActiveDocument.Bookmarks("OrigFollow").Range.Text = "Original will follow."
    Else
    ActiveDocument.Bookmarks("OrigFollow").Range.Text = "Original will not follow."
    End If

    ' If the document was originally protected,
    ' put back the same protection
    If Not (ProtectType = wdNoProtection) Then
    ActiveDocument.Protect ProtectType, True
    End If

    Unload Me
    Exit Sub

    ErrorHandler:
    If Err.Number = 5941 Then ' no such member of collection
    MsgBox "One or more bookmarks are missing from the template", , "Error"
    Else
    MsgBox "Error " & Err.Number & vbCr & Err.Description, , "Error"
    End If
    Unload Me
    End Sub

  5. #5
    New Lounger
    Join Date
    Aug 2002
    Location
    Houston, Texas, United Arab Emirates
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Templates & Outlook (Word 2000)

    I have been remiss in not thanking you earlier for your codes. That is very gracious of you to share with me the valuable time it took to develop this. I know because I, too, am digging through books to learn. Have not yet had a chance to do the input, but wanted to thank you for your offerings.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •