Consulting

Results 1 to 2 of 2

Thread: Getting a Macro Command Button to auto fill in document.

  1. #1

    Getting a Macro Command Button to auto fill in document.

    I'm having issues editing an existing Macro to get it to autofill at start up. Right now, a box pops up at start up asking if the document is a specific "status" type. I would like the response to auto fill in the header or the footer of the document. What is this missing or needs to be changed in the macro?

    Private Sub Actual_Click()
    Status.Hide
    ActiveDocument.CustomDocumentProperties("Status").Value = " "
    If ActiveWindow.View.SplitSpecial = wdPaneNone Then
    ActiveWindow.ActivePane.View.Type = wdNormalView
    Else
    ActiveWindow.View.Type = wdNormalView
    End If
    If ActiveWindow.View.SplitSpecial = wdPaneNone Then
    ActiveWindow.ActivePane.View.Type = wdPrintView
    Else
    ActiveWindow.View.Type = wdPrintView
    End If
    Application.ScreenRefresh
    Unload Status
    Load ContactNumber
    ContactNumber.Show
    End Sub

    Private Sub Drill_Click()
    Status.Hide
    ActiveDocument.CustomDocumentProperties("Status").Value = "This is a drill"
    If ActiveWindow.View.SplitSpecial = wdPaneNone Then
    ActiveWindow.ActivePane.View.Type = wdNormalView
    Else
    ActiveWindow.View.Type = wdNormalView
    End If
    If ActiveWindow.View.SplitSpecial = wdPaneNone Then
    ActiveWindow.ActivePane.View.Type = wdPrintView
    Else
    ActiveWindow.View.Type = wdPrintView
    End If
    Application.ScreenRefresh
    Unload Status

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,085
    Location
    Aside from the fact you don't need all that view-switching code, it's not apparent your code is actually doing anything with the header. What you need there is a DOCPROPERTY field in the header or footer referencing your 'Status'. The field code would look like:
    {DOCPROPERTY Status}
    Then, all the code you would need is:
    Private Sub Actual_Click() 
        Call UpdateFields 
    End Sub 
     
    Private Sub Drill_Click() 
        Call UpdateFields 
    End Sub 
     
     
    Sub UpdateFields() 
        Application.ScreenUpdating = False 
        With ActiveDocument 
            .PrintPreview 
            .ClosePrintPreview 
        End With 
        Application.ScreenUpdating = True 
    End Sub 
    
    
    Formatting tags added by mark007
    Cheers
    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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