View Single Post
 
Old 11-18-2014, 03:40 AM
tintin007 tintin007 is offline Windows XP Office 2007
Novice
 
Join Date: Nov 2014
Posts: 4
tintin007 is on a distinguished road
Default changed text box to content control

Hi,

Sorted out problem with not saving filename, this was down to me using text boxes and not content control text. I have learned some new stuff here, so thanks for your assistance.

final code below.

Code:
Private Sub CommandButton1_Click()
 
Dim strName As String
Dim strNum As String
Dim oCC As ContentControl
Const strPath As String = "C:\Documents and Settings\msaunders\My Documents\Unitam Installs" 'Which must exist!
        With ActiveDocument
        For Each oCC In .ContentControls
            If LCase(oCC.Title) = "panel number" Then
                If Trim(oCC.Range.Text) = oCC.PlaceholderText Then
                    oCC.Range.Select
                    MsgBox "Enter Panel Number"
                    Exit Sub
                Else
                    strNum = Trim(oCC.Range.Text)
                End If
            End If
            If LCase(oCC.Title) = "panel name" Then
                If Trim(oCC.Range.Text) = oCC.PlaceholderText Then
                    oCC.Range.Select
                    MsgBox "Enter Panel Name"
                    Exit Sub
                Else
                    strName = Trim(oCC.Range.Text)
                End If
            End If
        Next oCC
        .SaveAs FileName:=strPath & strNum & strName & ".docx"
        
    End With
End Sub
Reply With Quote