PDA

View Full Version : [SOLVED:] Getting a Macro Command Button to auto fill in document.



ljohnson15
08-29-2017, 12:31 PM
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

macropod
08-29-2017, 02:57 PM
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