Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How can I save a Word document using the contents of a textbox as the file name . . .

$
0
0

I have a merged document.  Each record is two pages.  I run the below script and it separates the larger file in to separate files (a record) and I can save them but I need to insert into the file name the value of a text box in the document.

I've tried several different things and can't figure out how to put the textbox value in the filename.  I'm new to VB . . .
Can someone please help!

Lisa

Sub BreakOnSection()


   ' Used to set criteria for moving through the document by section.
   Application.Browser.Target = wdBrowseSection

'Dim filename As Field
'Dim termdate As Field

    
    'A mailmerge document ends with a section break next page.
   'Subtracting one from the section count stop error message.
   For i = 1 To ((ActiveDocument.Sections.Count) - 1)
   
      'Select and copy the section text to the clipboard
      ActiveDocument.Bookmarks("\Section").Range.Copy

      'Create a new document to paste text from clipboard.
      Documents.Add
      Selection.Paste
       
'  filename = ActiveDocument. '("MEDID" & "TERMDATE").Name
 
 ' termdate = ActiveDocument.FormFields("TERMDATE").Range
       
       ' Removes the break that is copied at the end of the section, if any.
      Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
      Selection.Delete Unit:=wdCharacter, Count:=1


     ChangeFileOpenDirectory "\\vcuhshmo\groups\Enrollment\PCP Notification Letters\Specialist Termination\Test letters"
      docnum = docnum + 1
     ActiveDocument.SaveAs filename:="medid" & "termdate" & ".docx"
     ActiveDocument.Close
      ' Move the selection to the next section in the document
     Application.Browser.Next
   
   Next i
     
   ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>