Consulting

Results 1 to 2 of 2

Thread: Using MS Word Property Content Controls to create Filename

  1. #1

    Using MS Word Property Content Controls to create Filename

    Hi Peeps...



    I need help with saving a document PLEEZE.



    Using VBA, I know one can create a button to run a SaveAs procedure. But don't know how to compile it.



    I've created Property Content Controls by using INSERT>QUICK PARTS>DOCUMENT PROPERTY> then I've selected AUTHOR, and renamed it to ie. DRIVER (for vehicles). (I've created this to repeat the data in another field)



    I've created one for Company, Driver, RegNo and Disc.



    I would love to save the file with a push of a button into a file on the server with a new name: Disc-RegNo-Company-Driver
    (I know how to create the button, but have no idea what to put into the VBA field)
    (If it can be set up to create a new file - on the server - with the same name as the document, it would be a bonus...)



    Any help would be appreciated...
    Last edited by steffie85; 10-26-2017 at 05:51 AM.

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    Sub ScratchMacro()
    Dim strFileName As String
    Dim bInvalid As Boolean
      bInvalid = False
      
      With ActiveDocument
        Select Case True
          Case .SelectContentControlsByTitle("Disc.").Item(1).ShowingPlaceholderText: bInvalid = True
          Case .SelectContentControlsByTitle("RegNo").Item(1).ShowingPlaceholderText: bInvalid = True
          Case .SelectContentControlsByTitle("Driver").Item(1).ShowingPlaceholderText: bInvalid = True
          Case .SelectContentControlsByTitle("Company").Item(1).ShowingPlaceholderText: bInvalid = True
          Case Else
            strFileName = .SelectContentControlsByTitle("Disc.").Item(1).Range.Text & "-" & _
            .SelectContentControlsByTitle("RegNo").Item(1).Range.Text & "-" & _
            .SelectContentControlsByTitle("Company").Item(1).Range.Text & "-" & _
            .SelectContentControlsByTitle("Driver").Item(1).Range.Text
        End Select
      End With
        If bInvalid Then
          MsgBox "File name not defined from document content."
          Exit Sub
        End If
        With Dialogs(wdDialogFileSaveAs)
          .Name = strFileName
          .Show
        End With
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

Tags for this Thread

Posting Permissions

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