Using VBA to Add a Fax Cover Sheet to Locked Template

User avatar
arroway
3StarLounger
Posts: 368
Joined: 04 Jan 2012, 22:43

Using VBA to Add a Fax Cover Sheet to Locked Template

Post by arroway »

Hello. I have a locked Word form template which lives on our server. We just got a printer which has the capability of faxing and we'd like to take advantage of that but our policy says all faxes must include a fax cover sheet. To make things easier for folks, we have 'pre-filled' cover sheets, custom made for many of the places we fax to. I'm looking for a VBA way of inserting the custom fax sheet at the beginning of the document. Unless there's another easier way, I'm thinking the VBA could: Unlock the form, ask which custom fax form to use, open that document when selected and cut the whole thing, insert it at the beginning of the document, then relock the form. I could use an Autotext entry but with all the different types of fax forms we have, Autotext wouldn't seem to work. I'm not entirely sure if the way I'm thinking this might happen is the best way of getting the job done but I'm hoping one of you BRILLIANT folks might be able to help me out. Can you help?

Thanks,
Dax
It takes 2 to tango; unless you speak binary; then it takes 10.

User avatar
HansV
Administrator
Posts: 78494
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Using VBA to Add a Fax Cover Sheet to Locked Template

Post by HansV »

See if the following macro does what you want:

Code: Select all

Sub InsertCoverSheet()
    Dim strFile As String
    With Application.FileDialog(1) ' msoFileDialogOpen
        .Title = "Select a Fax Cover Sheet"
        If .Show Then
            strFile = .SelectedItems(1)
        Else
            MsgBox "No cover sheet selected!", vbExclamation
            Exit Sub
        End If
    End With
    On Error GoTo ErrHandler
    Application.ScreenUpdating = False
    ActiveDocument.Unprotect ' Password:="secret"
    Selection.HomeKey Unit:=wdStory
    Selection.InsertBreak Type:=wdSectionBreakNextPage
    Selection.HomeKey Unit:=wdStory
    Selection.InsertFile FileName:=strFile
    
ExitHandler:
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True ' , Password:="secret"
    Application.ScreenUpdating = True
    Exit Sub

ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
End Sub
Note: the fax cover will be protected too. I don't know if that suits your purpose.
Best wishes,
Hans

User avatar
arroway
3StarLounger
Posts: 368
Joined: 04 Jan 2012, 22:43

Re: Using VBA to Add a Fax Cover Sheet to Locked Template

Post by arroway »

That's perfect! I mean...BRILLIANT!!! One last peice; our faxes are in H:/admin/faxsheets/ What would I add (and where) to the code to have the dialog box go there?
It takes 2 to tango; unless you speak binary; then it takes 10.

User avatar
HansV
Administrator
Posts: 78494
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Using VBA to Add a Fax Cover Sheet to Locked Template

Post by HansV »

Below the line

Code: Select all

        .Title = "Select a Fax Cover Sheet"
insert the following new line:

Code: Select all

        .InitialFileName = "H:\Admin\FaxSheets\"
Best wishes,
Hans

User avatar
arroway
3StarLounger
Posts: 368
Joined: 04 Jan 2012, 22:43

Re: Using VBA to Add a Fax Cover Sheet to Locked Template

Post by arroway »

:bananas: :bananas: :bananas: You are SO "THE MAN" it's not even funny! THANK YOU!!! :bananas: :bananas: :bananas:
It takes 2 to tango; unless you speak binary; then it takes 10.